MediaPlayer disables playback too early on Lollipop when the screen is off

I am having a problem with MediaPlayer on Lollipop devices. Basically, when the deviceโ€™s screen is off (that is, the user has locked the device), playback continues, but ends about 1 to 2 seconds too soon. This does not happen if the screen is on.

I have an onCompletionListener on MediaPlayer:

@Override
public void onCompletion(final MediaPlayer mediaPlayer) {
    int progress = mediaPlayer.getCurrentPosition();
    int duration = mediaPlayer.getDuration();
    Log.d("PlaybackController", "progress: " + progress + " duration: " + duration);
    Log.d("PlaybackController", "Delay: " + (duration - progress)); // I'm seeing a difference of 1 - 3 seconds :(.
    mServiceHandler.postDelayed(new Runnable() {
        @Override
        public void run() {
            broadcastCompleted();
        }
    }, Math.max(duration - progress, 0));
}

Usually it prints: Delay: [1500 - 3000]. I was wondering if there is a trace lock that I am missing, but I am doing the correct locks mentioned here: http://developer.android.com/guide/topics/media/mediaplayer.html , which include PARTIAL_WAKE_LOCK and WifiLock. Is there anything else I am missing?

+4
2

, , MediaPlayer Android 5.0.1 NuPlayer. NuPlayer Android 5.0.1 . : https://code.google.com/p/android/issues/detail?id=94069&thanks=94069&ts=1420659450

, , Android 5.0.1:

, Android NuPlayer. , :

  • Android
  • " "
  • " " 7 .
    • , : " X ".
    • 7 : " !"
  • , " " " "
  • " NuPlayer ()" "".
+2

: MediaPlayer :

playerToPrepare.setWakeMode(context, PowerManager.PARTIAL_WAKE_LOCK);

, , MediaPlayer .

- ---

NuPlayer Android Lollipop 5.x?, NuPlayer, , NuPlayer .

Android, , AwesomePlayer . Lollipop NuPlayer , , , NuPlayer .

SystemProperties.java , android.os (it JNI-, ).

, Lollipop/5.0, AwesomePlayer , (, ):

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);                
    }
}
0

All Articles