Update : Installing partial trace lock on MediaPlayer fixes this problem:
playerToPrepare.setWakeMode(context, PowerManager.PARTIAL_WAKE_LOCK);
Partial blocking of a track should not have too much effect, and it seems that MediaPlayer itself clears it when playback is completed.
- Original answer ---
So, I finally found a way to safely detect whether or not NuPlayer
will be used or not on Lollipop. It seems like a better strategy is to tell the user to open the developer’s settings and enable AwesomePlayer
until Google installs NuPlayer
. Unfortunately, there is no good way to change this parameter for the user, we can just read its value if you are not subscribed as a system application.
This approach checks the values ​​of the properties of the Android system to see if the user has allowed the use of AwesomePlayer or not in the developer’s settings. Since Lollipop has NuPlayer by default, if this value is disabled, we know that NuPlayer will be used.
Drop SystemProperties.java into your project to access system properties, do not change its package name from android.os
(it calls up to the corresponding JNI methods, so you need to stay the same).
Now you can check if the phone is Lollipop / 5.0 if AwesomePlayer
turned on and acts accordingly if it is not (for example, by opening the developer’s 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); } }
source share