Bug 1464922 - Remove HTMLMediaElement::mAttemptPlayUponLoadedMetadata. r?bryce
We don't need to track this state anymore, as we don't need to delay calling
MediaDecoder::Play() or delay firing the "playing" event anymore.
MozReview-Commit-ID: E3B9l6ep7FP
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -1798,17 +1798,16 @@ HTMLMediaElement::AbortExistingLoads()
mHaveQueuedSelectResource = false;
mSuspendedForPreloadNone = false;
mDownloadSuspendedByCache = false;
mMediaInfo = MediaInfo();
mIsEncrypted = false;
mPendingEncryptedInitData.Reset();
mWaitingForKey = NOT_WAITING_FOR_KEY;
mSourcePointer = nullptr;
- mAttemptPlayUponLoadedMetadata = false;
mTags = nullptr;
if (mNetworkState != NETWORK_EMPTY) {
NS_ASSERTION(!mDecoder && !mSrcStream,
"How did someone setup a new stream/decoder already?");
// ChangeNetworkState() will call UpdateAudioChannelPlayingState()
// indirectly which depends on mPaused. So we need to update mPaused first.
@@ -4081,27 +4080,18 @@ HTMLMediaElement::PlayInternal(ErrorResu
// Even if we just did Load() or ResumeLoad(), we could already have a decoder
// here if we managed to clone an existing decoder.
if (mDecoder) {
if (mDecoder->IsEnded()) {
SetCurrentTime(0);
}
if (!mPausedForInactiveDocumentOrChannel) {
- if (mReadyState < HAVE_METADATA) {
- // We don't know whether the autoplay policy will allow us to play yet,
- // as we don't yet know whether the media has audio tracks. So delay
- // starting playback until we've loaded metadata.
- mAttemptPlayUponLoadedMetadata = true;
- } else {
- mDecoder->Play();
- }
- }
- } else if (mReadyState < HAVE_METADATA) {
- mAttemptPlayUponLoadedMetadata = true;
+ mDecoder->Play();
+ }
}
if (mCurrentPlayRangeStart == -1.0) {
mCurrentPlayRangeStart = CurrentTime();
}
const bool oldPaused = mPaused;
mPaused = false;
@@ -4152,18 +4142,17 @@ HTMLMediaElement::PlayInternal(ErrorResu
DispatchAsyncEvent(NS_LITERAL_STRING("waiting"));
break;
case HAVE_FUTURE_DATA:
case HAVE_ENOUGH_DATA:
FireTimeUpdate(false);
NotifyAboutPlaying();
break;
}
- } else if (mReadyState >= HAVE_FUTURE_DATA &&
- !mAttemptPlayUponLoadedMetadata) {
+ } else if (mReadyState >= HAVE_FUTURE_DATA) {
// 7. Otherwise, if the media element's readyState attribute has the value
// HAVE_FUTURE_DATA or HAVE_ENOUGH_DATA, take pending play promises and
// queue a task to resolve pending play promises with the result.
AsyncResolvePendingPlayPromises();
}
// 8. Set the media element's autoplaying flag to false. (Already done.)
@@ -4984,17 +4973,17 @@ HTMLMediaElement::FinishDecoderSetup(Med
// We may want to suspend the new stream now.
// This will also do an AddRemoveSelfReference.
NotifyOwnerDocumentActivityChanged();
if (mPausedForInactiveDocumentOrChannel) {
mDecoder->Suspend();
}
- if (!mPaused && !mAttemptPlayUponLoadedMetadata) {
+ if (!mPaused) {
SetPlayedOrSeeked(true);
if (!mPausedForInactiveDocumentOrChannel) {
mDecoder->Play();
}
}
return NS_OK;
}
@@ -6031,26 +6020,16 @@ HTMLMediaElement::ChangeReadyState(nsMed
DDLOG(DDLogCategory::Property, "ready_state", gReadyStateToString[aState]);
if (mNetworkState == NETWORK_EMPTY) {
return;
}
UpdateAudioChannelPlayingState();
- if (oldState < HAVE_METADATA && mReadyState >= HAVE_METADATA &&
- mAttemptPlayUponLoadedMetadata) {
- mAttemptPlayUponLoadedMetadata = false;
- if (!mPaused && !IsAllowedToPlay()) {
- mPaused = true;
- DispatchAsyncEvent(NS_LITERAL_STRING("pause"));
- AsyncRejectPendingPlayPromises(NS_ERROR_DOM_MEDIA_NOT_ALLOWED_ERR);
- }
- }
-
// Handle raising of "waiting" event during seek (see 4.8.10.9)
// or
// 4.8.12.7 Ready states:
// "If the previous ready state was HAVE_FUTURE_DATA or more, and the new
// ready state is HAVE_CURRENT_DATA or less
// If the media element was potentially playing before its readyState
// attribute changed to a value lower than HAVE_FUTURE_DATA, and the element
// has not ended playback, and playback has not stopped due to errors,
@@ -6195,17 +6174,16 @@ HTMLMediaElement::CheckAutoplayDataReady
UpdateSrcMediaStreamPlaying();
UpdateAudioChannelPlayingState();
if (mDecoder) {
SetPlayedOrSeeked(true);
if (mCurrentPlayRangeStart == -1.0) {
mCurrentPlayRangeStart = CurrentTime();
}
- MOZ_ASSERT(!mAttemptPlayUponLoadedMetadata);
mDecoder->Play();
} else if (mSrcStream) {
SetPlayedOrSeeked(true);
}
// For blocked media, the event would be pending until it is resumed.
DispatchAsyncEvent(NS_LITERAL_STRING("play"));
@@ -6559,17 +6537,16 @@ HTMLMediaElement::SuspendOrResumeElement
mDecoder->Pause();
mDecoder->Suspend();
}
mEventDeliveryPaused = aSuspendEvents;
} else {
if (mDecoder) {
mDecoder->Resume();
if (!mPaused && !mDecoder->IsEnded()) {
- MOZ_ASSERT(!mAttemptPlayUponLoadedMetadata);
mDecoder->Play();
}
}
if (mEventDeliveryPaused) {
mEventDeliveryPaused = false;
DispatchPendingMediaEvents();
}
}
--- a/dom/html/HTMLMediaElement.h
+++ b/dom/html/HTMLMediaElement.h
@@ -1816,23 +1816,16 @@ private:
// True if media element has been marked as 'tainted' and can't
// participate in video decoder suspending.
bool mHasSuspendTaint = false;
// True if media element has been forced into being considered 'hidden'.
// For use by mochitests. Enabling pref "media.test.video-suspend"
bool mForcedHidden = false;
- // True if we attempted to play before the media element had loaded
- // metadata, and we need to attempt the play once we reach loaded metadata.
- // If autoplay is disabled, we can't decide whether to allow a play()
- // until we've loaded metadata, as we need to know whether the resource
- // has an audio track.
- bool mAttemptPlayUponLoadedMetadata = false;
-
// True if audio tracks and video tracks are constructed and added into the
// track list, false if all tracks are removed from the track list.
bool mMediaTracksConstructed = false;
Visibility mVisibilityState = Visibility::UNTRACKED;
UniquePtr<ErrorSink> mErrorSink;