title: MediaPlayer cutting off playback too early on Lollipop when Screen is off
body: <p>I've been running into an issue with the MediaPlayer on Lollipop devices.  Basically when the device screen is off (i.e. user locked the device) the playback continues, but ends about 1 - 2 seconds too early.  This doesn't happen when the screen is on though.</p>
  
  <p>I have an onCompletionListener on the MediaPlayer:</p>
  
  <pre><code>@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));
  }
  </code></pre>
  
  <p>This usually prints: <code>Delay: [1500 - 3000]</code>.  I was wondering if there was a wake lock I'm missing, but I'm making the correct locks mentioned here: <a href="http://developer.android.com/guide/topics/media/mediaplayer.html" rel="nofollow">http://developer.android.com/guide/topics/media/mediaplayer.html</a>, which include a PARTIAL_WAKE_LOCK and a WifiLock. Is there something else I'm missing?</p>