diff --git a/dom/html/HTMLMediaElement.cpp b/dom/html/HTMLMediaElement.cpp index 88c494ffd01c..61a6339e5846 100644 --- a/dom/html/HTMLMediaElement.cpp +++ b/dom/html/HTMLMediaElement.cpp @@ -3740,13 +3740,13 @@ void HTMLMediaElement::SeekCompleted() { mPlayingBeforeSeek = false; SetPlayedOrSeeked(true); - if (mTextTrackManager) { - mTextTrackManager->DidSeek(); - } FireTimeUpdate(false); DispatchAsyncEvent(NS_LITERAL_STRING("seeked")); // We changed whether we're seeking so we need to AddRemoveSelfReference AddRemoveSelfReference(); + if (mTextTrackManager) { + mTextTrackManager->DidSeek(); + } if (mCurrentPlayRangeStart == -1.0) { mCurrentPlayRangeStart = CurrentTime(); } diff --git a/dom/html/TextTrackManager.cpp b/dom/html/TextTrackManager.cpp index 773dbc5236ca..44ea8e6a36d6 100644 --- a/dom/html/TextTrackManager.cpp +++ b/dom/html/TextTrackManager.cpp @@ -193,7 +193,8 @@ TextTrackManager::RemoveTextTrack(TextTrack* aTextTrack, bool aPendingListOnly) TextTrackCueList* removeCueList = aTextTrack->GetCues(); if (removeCueList) { for (uint32_t i = 0; i < removeCueList->Length(); ++i) { - mNewCues->RemoveCue(*((*removeCueList)[i])); + ErrorResult dummyRv; + mNewCues->RemoveCue(*((*removeCueList)[i]), dummyRv); } DispatchTimeMarchesOn(); } @@ -205,9 +206,6 @@ TextTrackManager::DidSeek() if (mTextTracks) { mTextTracks->DidSeek(); } - if (mMediaElement) { - mLastTimeMarchesOnCalled = mMediaElement->CurrentTime(); - } mHasSeeked = true; } @@ -266,7 +264,8 @@ void TextTrackManager::NotifyCueRemoved(TextTrackCue& aCue) { if (mNewCues) { - mNewCues->RemoveCue(aCue); + ErrorResult dummyRv; + mNewCues->RemoveCue(aCue, dummyRv); } DispatchTimeMarchesOn(); } @@ -533,8 +532,7 @@ TextTrackManager::TimeMarchesOn() } nsCOMPtr window = do_QueryInterface(parentObject); - if (mMediaElement && - (!(mMediaElement->GetPlayedOrSeeked())|| mMediaElement->Seeking())) { + if (mMediaElement && !(mMediaElement->GetPlayedOrSeeked())) { return; } @@ -572,7 +570,8 @@ TextTrackManager::TimeMarchesOn() } for (uint32_t i = 0; i < currentCues->Length(); ++i) { TextTrackCue* cue = (*currentCues)[i]; - otherCues->RemoveCue(*cue); + ErrorResult dummy; + otherCues->RemoveCue(*cue, dummy); } // Step 4. @@ -697,10 +696,6 @@ TextTrackManager::TimeMarchesOn() TextTrack* ttrack = affectedTracks[i]; if (ttrack) { ttrack->DispatchTrustedEvent(NS_LITERAL_STRING("cuechange")); - HTMLTrackElement* trackElement = ttrack->GetTrackElement(); - if (trackElement) { - trackElement->DispatchTrackRunnable(NS_LITERAL_STRING("cuechange")); - } } } diff --git a/dom/media/TextTrack.cpp b/dom/media/TextTrack.cpp index 1eb21ccf832d..26834089113c 100644 --- a/dom/media/TextTrack.cpp +++ b/dom/media/TextTrack.cpp @@ -160,6 +160,10 @@ TextTrack::UpdateActiveCueList() return; } + // Flag that indicates whether or not this call of UpdateActiveCueList has + // changed the activeCueList. + bool hasChanged = false; + // If we are dirty, i.e. an event happened that may cause the sorted mCueList // to have changed like a seek or an insert for a cue, than we need to rebuild // the active cue list from scratch. @@ -175,6 +179,7 @@ TextTrack::UpdateActiveCueList() for (uint32_t i = mActiveCueList->Length(); i > 0; i--) { if ((*mActiveCueList)[i - 1]->EndTime() < playbackTime) { mActiveCueList->RemoveCueAt(i - 1); + hasChanged = true; } } // Add all the cues, starting from the position of the last cue that was @@ -185,6 +190,16 @@ TextTrack::UpdateActiveCueList() (*mCueList)[mCuePos]->StartTime() <= playbackTime; mCuePos++) { if ((*mCueList)[mCuePos]->EndTime() >= playbackTime) { mActiveCueList->AddCue(*(*mCueList)[mCuePos]); + hasChanged = true; + } + } + + if (hasChanged) { + RefPtr asyncDispatcher = + new AsyncEventDispatcher(this, NS_LITERAL_STRING("cuechange"), false); + asyncDispatcher->PostDOMEvent(); + if (mTrackElement) { + mTrackElement->DispatchTrackRunnable(NS_LITERAL_STRING("cuechange")); } } } diff --git a/dom/media/TextTrackCueList.cpp b/dom/media/TextTrackCueList.cpp index f3fe66662adb..e3f98d38d7c1 100644 --- a/dom/media/TextTrackCueList.cpp +++ b/dom/media/TextTrackCueList.cpp @@ -103,12 +103,6 @@ TextTrackCueList::RemoveCue(TextTrackCue& aCue, ErrorResult& aRv) mList.RemoveElement(&aCue); } -void -TextTrackCueList::RemoveCue(TextTrackCue& aCue) -{ - mList.RemoveElement(&aCue); -} - void TextTrackCueList::RemoveCueAt(uint32_t aIndex) { diff --git a/dom/media/TextTrackCueList.h b/dom/media/TextTrackCueList.h index 8a77045f76e6..aa88f3c062cb 100644 --- a/dom/media/TextTrackCueList.h +++ b/dom/media/TextTrackCueList.h @@ -50,7 +50,6 @@ public: // from the end of the current array should be more efficient than a general // sort step after all cues are loaded. void AddCue(TextTrackCue& aCue); - void RemoveCue(TextTrackCue& aCue); void RemoveCue(TextTrackCue& aCue, ErrorResult& aRv); void RemoveCueAt(uint32_t aIndex); void RemoveAll(); diff --git a/dom/media/test/test_texttrackcue.html b/dom/media/test/test_texttrackcue.html index 08a2016ec540..29fc9b3cf869 100644 --- a/dom/media/test/test_texttrackcue.html +++ b/dom/media/test/test_texttrackcue.html @@ -83,10 +83,6 @@ SpecialPowers.pushPrefEnv({"set": [["media.webvtt.regions.enabled", true]]}, is(cue.endTime, 0.71, "Cue's end time should be 0.71."); cue.pauseOnExit = true; is(cue.pauseOnExit, true, "Cue's pause on exit flag should be true."); - video.addEventListener("pause", function pauseOnExit() { - video.removeEventListener("pause", pauseOnExit, false); - video.play(); - }); var exceptionHappened; function checkPercentageValue(prop) {