From 1e6be7285d4dc8b494c70aef8d2ed8b8c1d8e0de Mon Sep 17 00:00:00 2001 From: Chong Zhang Date: Wed, 6 May 2015 13:14:59 -0700 Subject: MediaPlayer: pause media time when buffering bug: 20500732 Change-Id: Ife7f75f5cc587af56451c85ea8adbdc380f38348 --- media/java/android/media/MediaPlayer.java | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'media') diff --git a/media/java/android/media/MediaPlayer.java b/media/java/android/media/MediaPlayer.java index 6ec10c7..b3c1b4d 100644 --- a/media/java/android/media/MediaPlayer.java +++ b/media/java/android/media/MediaPlayer.java @@ -2824,6 +2824,13 @@ public class MediaPlayer implements SubtitleController.Listener mSubtitleController.selectDefaultTrack(); } break; + case MEDIA_INFO_BUFFERING_START: + case MEDIA_INFO_BUFFERING_END: + TimeProvider timeProvider = mTimeProvider; + if (timeProvider != null) { + timeProvider.onBuffering(msg.arg1 == MEDIA_INFO_BUFFERING_START); + } + break; } if (mOnInfoListener != null) { @@ -3362,6 +3369,7 @@ public class MediaPlayer implements SubtitleController.Listener private MediaPlayer mPlayer; private boolean mPaused = true; private boolean mStopped = true; + private boolean mBuffering; private long mLastReportedTime; private long mTimeAdjustment; // since we are expecting only a handful listeners per stream, there is @@ -3455,12 +3463,22 @@ public class MediaPlayer implements SubtitleController.Listener } /** @hide */ + public void onBuffering(boolean buffering) { + synchronized (this) { + if (DEBUG) Log.d(TAG, "onBuffering: " + buffering); + mBuffering = buffering; + scheduleNotification(REFRESH_AND_NOTIFY_TIME, 0 /* delay */); + } + } + + /** @hide */ public void onStopped() { synchronized(this) { if (DEBUG) Log.d(TAG, "onStopped"); mPaused = true; mStopped = true; mSeeking = false; + mBuffering = false; scheduleNotification(NOTIFY_STOP, 0 /* delay */); } } @@ -3481,6 +3499,7 @@ public class MediaPlayer implements SubtitleController.Listener synchronized(this) { mStopped = false; mSeeking = true; + mBuffering = false; scheduleNotification(NOTIFY_SEEK, 0 /* delay */); } } @@ -3683,7 +3702,7 @@ public class MediaPlayer implements SubtitleController.Listener nanoTime >= mLastNanoTime + MAX_NS_WITHOUT_POSITION_CHECK) { try { mLastTimeUs = mPlayer.getCurrentPosition() * 1000L; - mPaused = !mPlayer.isPlaying(); + mPaused = !mPlayer.isPlaying() || mBuffering; if (DEBUG) Log.v(TAG, (mPaused ? "paused" : "playing") + " at " + mLastTimeUs); } catch (IllegalStateException e) { if (mPausing) { -- cgit v1.1