prevent使用NuPlayer在Android棒棒糖5.x的我的音乐应用程序吗? [英] Prevent my audio app using NuPlayer on Android Lollipop 5.x?

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

问题描述

我有一个音频应用程序,播放多音轨在同一时间,每个都有自己的的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.

只要曲目都设有codeD的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.

但在棒棒堂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:

playerTo prepare.setWakeMode(背景下,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 将被用于或不棒棒糖。好像现在最好的策略是通知用户打开开发人员设置并启用 AwesomePlayer ,直到谷歌修复 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与否开发设置下。由于棒棒糖有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).

您现在可以检查手机棒棒糖/ 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);                
    }
}

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

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