在 Android Lollipop 5.x 上使用 NuPlayer 阻止我的音频应用程序? [英] Prevent my audio app using NuPlayer on Android Lollipop 5.x?

查看:17
本文介绍了在 Android Lollipop 5.x 上使用 NuPlayer 阻止我的音频应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个音频应用,可以同时播放多首曲目,每首曲目都有自己的 mediaPlayer.每首曲目都相当长,超过两分钟.

I have an audio app that plays multiple tracks at the same time, each with their own mediaPlayer. Each track is reasonably long, upwards of two minutes.

只要将曲目编码为 ogg 文件,一切都可以在 Android 4.x 上正常运行.我还没有遇到过运行股票 4.x 的设备在此设置中出现任何音频问题.

So long as the tracks are encoded as ogg files, everything works great on Android 4.x. I've yet to encounter a device running stock 4.x that has any audio problems with this setup.

但是在 Lollipop 5.x 上存在各种各样的音频问题 - 卡顿、音轨中断和蓝牙音频几乎从来没有工作过.

But on Lollipop 5.x there are a wide variety of audio problems - stuttering, tracks cutting out, and bluetooth audio almost never seems to work.

我发现在 5.x 中进入开发者选项并取消选中使用 Nuplayer(实验性)"可以立即解决这些问题并恢复到 4.x 级别的性能.

I've discovered that going into Developer options in 5.x and unchecking "use Nuplayer (experimental)" instantly solves these problems and returns to 4.x levels of performance.

有没有办法以编程方式强制我的应用程序使用 4.x 媒体堆栈(我认为它称为 Awesomeplayer?)而不使用新的 Nuplayer 系统?至少在我能发现 Nuplayer 问题的根源之前?

Is there a way I can programmatically force my app to use the 4.x media stack (I believe it's called Awesomeplayer?) and not to use the new Nuplayer system? At least until I can discover the source of the Nuplayer problems?

推荐答案

更新:在 MediaPlayer 上设置部分唤醒锁定可解决此问题:

Update: Setting a partial wake lock on the MediaPlayer resolves this problem:

playerToPrepare.setWakeMode(context, PowerManager.PARTIAL_WAKE_LOCK);

部分唤醒锁定不应产生太大影响,而且 MediaPlayer 本身似乎会在播放完成时对此进行清理.

A partial wake lock shouldn't have too big of an impact, and it seems like MediaPlayer itself cleans this up when playback completes.

-- 原始答案 ---

-- Original Answer ---

所以,我终于找到了一种安全检测 NuPlayer 是否会在 Lollipop 上使用的方法.似乎目前最好的策略是通知用户打开开发者设置并启用 AwesomePlayer,直到 Google 修复 NuPlayer.遗憾的是,没有好的方法可以为用户更改此设置,除非您作为系统应用程序签名,否则我们只能读取其值.

So, I finally found a way to safely detect wether or not NuPlayer will be used or not on Lollipop. Seems like the best strategy for now is to inform the user to open Developer Settings and enable AwesomePlayer until Google fixes NuPlayer. Sadly, there's no good way to change this setting for the user, we can just read its value unless you're signed as a system application.

此方法会检查 Android 的系统属性值,以查看用户是否在开发人员设置下启用了 AwesomePlayer.由于 Lollipop 默认启用 NuPlayer,如果禁用此值,我们知道将使用 NuPlayer.

This approach checks Android's system properties values to see if the user have enabled the use of AwesomePlayer or not under Developer Settings. Since Lollipop have NuPlayer on by default, if this value is disabled, we know NuPlayer will be used.

SystemProperties.java拖放到您的项目中以访问读取系统属性,不要更改它的包名来自 android.os(它调用相应的 JNI 方法,因此需要保持不变).

Drop SystemProperties.java into your project for access to read the system properties, do not change its package name from android.os (it calls through to its corresponding JNI methods, so needs to stay the same).

您现在可以检查手机是否为 Lollipop/5.0,是否启用了 AwesomePlayer,如果未启用,请采取相应措施(例如,通过打开开发者设置):

You can now check if the phone is Lollipop/5.0, if AwesomePlayer is enabled, and act accordingly if it's not (e.g. by opening the Developer Settings):

public void openDeveloperSettingsIfAwesomePlayerNotActivated(final Context context) {
    final boolean useAwesome = SystemProperties.getBoolean("persist.sys.media.use-awesome", false);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && !useAwesome) {
        final Intent intent = new Intent(Settings.ACTION_APPLICATION_DEVELOPMENT_SETTINGS);
        context.startActivity(intent);                
    }
}

这篇关于在 Android Lollipop 5.x 上使用 NuPlayer 阻止我的音频应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆