Bug 1317576. Part 6 - ensure 'playbackEnded' is notified when seeking to the end on a paused media element. r=cpearce
authorJW Wang <jwwang@mozilla.com>
Tue, 15 Nov 2016 12:06:17 +0800
changeset 322677 6f39dfa71498b1398c4a6573dafc0ae3283c0409
parent 322676 16b9dfb4ca47b34e41e300b59fc1804a4b20abcc
child 322678 1f9d289e8272f27659bf980528b6d89f61f7ac87
push id21
push usermaklebus@msu.edu
push dateThu, 01 Dec 2016 06:22:08 +0000
reviewerscpearce
bugs1317576
milestone53.0a1
Bug 1317576. Part 6 - ensure 'playbackEnded' is notified when seeking to the end on a paused media element. r=cpearce MozReview-Commit-ID: 4fzru2oHaPV
dom/media/MediaDecoderStateMachine.cpp
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -1048,18 +1048,17 @@ public:
                  "Must have timer scheduled");
       return;
     }
 
     // StopPlayback in order to reset the IsPlaying() state so audio
     // is restarted correctly.
     mMaster->StopPlayback();
 
-    if (mMaster->mPlayState == MediaDecoder::PLAY_STATE_PLAYING &&
-        !mSentPlaybackEndedEvent) {
+    if (!mSentPlaybackEndedEvent) {
       int64_t clockTime = std::max(mMaster->AudioEndTime(), mMaster->VideoEndTime());
       clockTime = std::max(int64_t(0), std::max(clockTime, mMaster->Duration().ToMicroseconds()));
       mMaster->UpdatePlaybackPosition(clockTime);
 
       // Ensure readyState is updated before firing the 'ended' event.
       mMaster->UpdateNextFrameStatus();
 
       mMaster->mOnPlaybackEvent.Notify(MediaEventType::PlaybackEnded);
@@ -1502,16 +1501,22 @@ SeekingState::SeekCompleted()
   bool isLiveStream = Resource()->IsLiveStream();
   if (newCurrentTime == mMaster->Duration().ToMicroseconds() && !isLiveStream) {
     // Seeked to end of media. Explicitly finish the queues so DECODING
     // will transition to COMPLETED immediately. Note we don't do
     // this when playing a live stream, since the end of media will advance
     // once we download more data!
     AudioQueue().Finish();
     VideoQueue().Finish();
+
+    // We won't start MediaSink when paused. m{Audio,Video}Completed will
+    // remain false and 'playbackEnded' won't be notified. Therefore we
+    // need to set these flags explicitly when seeking to the end.
+    mMaster->mAudioCompleted = true;
+    mMaster->mVideoCompleted = true;
   }
 
   // We want to resolve the seek request prior finishing the first frame
   // to ensure that the seeked event is fired prior loadeded.
   mSeekJob.Resolve(__func__);
 
   // Notify FirstFrameLoaded now if we haven't since we've decoded some data
   // for readyState to transition to HAVE_CURRENT_DATA and fire 'loadeddata'.