Bug 1317576. Part 6 - ensure 'playbackEnded' is notified when seeking to the end on a paused media element.
MozReview-Commit-ID: 4fzru2oHaPV
--- 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'.