Bug 1302350 - part6 : ensure loading process doens't be interrupted even media element can't be played.
We don't want to stop the loading process even we canceled the play operation.
MozReview-Commit-ID: FyPqBlDKYo0
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -2997,16 +2997,17 @@ HTMLMediaElement::NotifyXPCOMShutdown()
{
ShutdownDecoder();
}
void
HTMLMediaElement::Play(ErrorResult& aRv)
{
if (!IsAllowedToPlay()) {
+ MaybeDoLoad();
return;
}
nsresult rv = PlayInternal();
if (NS_FAILED(rv)) {
aRv.Throw(rv);
}
}
@@ -3015,19 +3016,17 @@ nsresult
HTMLMediaElement::PlayInternal()
{
// Play was not blocked so assume user interacted with the element.
mHasUserInteraction = true;
StopSuspendingAfterFirstFrame();
SetPlayedOrSeeked(true);
- if (mNetworkState == nsIDOMHTMLMediaElement::NETWORK_EMPTY) {
- DoLoad();
- }
+ MaybeDoLoad();
if (mSuspendedForPreloadNone) {
ResumeLoad(PRELOAD_ENOUGH);
}
// 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()) {
@@ -3083,19 +3082,28 @@ HTMLMediaElement::PlayInternal()
DispatchAsyncEvent(NS_LITERAL_STRING("playing"));
break;
}
}
return NS_OK;
}
+void
+HTMLMediaElement::MaybeDoLoad()
+{
+ if (mNetworkState == nsIDOMHTMLMediaElement::NETWORK_EMPTY) {
+ DoLoad();
+ }
+}
+
NS_IMETHODIMP HTMLMediaElement::Play()
{
if (!IsAllowedToPlay()) {
+ MaybeDoLoad();
return NS_OK;
}
return PlayInternal();
}
HTMLMediaElement::WakeLockBoolWrapper&
HTMLMediaElement::WakeLockBoolWrapper::operator=(bool val)
--- a/dom/html/HTMLMediaElement.h
+++ b/dom/html/HTMLMediaElement.h
@@ -1260,16 +1260,19 @@ protected:
void ResumeFromAudioChannelBlocked();
bool IsSuspendedByAudioChannel() const;
void SetAudioChannelSuspended(SuspendTypes aSuspend);
// A method to check whether the media element is allowed to start playback.
bool IsAllowedToPlay();
+ // If the network state is empty and then we would trigger DoLoad().
+ void MaybeDoLoad();
+
// True if the tab which media element belongs to has been to foreground at
// least once or activated by manually clicking the unblocking tab icon.
bool IsTabActivated() const;
bool IsAudible() const;
bool HaveFailedWithSourceNotSupportedError() const;
void OpenUnsupportedMediaWithExtenalAppIfNeeded();