Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1e6be728 authored by Chong Zhang's avatar Chong Zhang
Browse files

MediaPlayer: pause media time when buffering

bug: 20500732
Change-Id: Ife7f75f5cc587af56451c85ea8adbdc380f38348
parent c1125ded
Loading
Loading
Loading
Loading
+20 −1
Original line number Diff line number Diff line
@@ -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
@@ -3454,6 +3462,15 @@ 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) {
@@ -3461,6 +3478,7 @@ public class MediaPlayer implements SubtitleController.Listener
                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) {