Bug 1317576. Part 6 - ensure 'playbackEnded' is notified when seeking to the end on a paused media element. draft
authorJW Wang <jwwang@mozilla.com>
Tue, 15 Nov 2016 12:06:17 +0800
changeset 439473 6f9f800e338bc09179f1b7818d93395fff92993a
parent 439472 08bdb03b70964c912a002f11fd413eaf85cd4af6
child 439474 78bf3c347bf0228f6a28ca5b088f61dc47b476dd
push id36009
push userjwwang@mozilla.com
push dateWed, 16 Nov 2016 02:24:06 +0000
bugs1317576
milestone53.0a1
Bug 1317576. Part 6 - ensure 'playbackEnded' is notified when seeking to the end on a paused media element. 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'.