diff --git a/dom/html/HTMLMediaElement.cpp b/dom/html/HTMLMediaElement.cpp index ebf6c7fc67fb..4e6476b216a3 100644 --- a/dom/html/HTMLMediaElement.cpp +++ b/dom/html/HTMLMediaElement.cpp @@ -6656,9 +6656,11 @@ void HTMLMediaElement::NotifyFullScreenChanged() { const bool isInFullScreen = IsInFullScreen(); if (isInFullScreen) { StartMediaControlKeyListenerIfNeeded(); - MOZ_ASSERT(mMediaControlKeyListener->IsStarted(), - "Failed to start the listener when entering fullscreen!"); + if (!mMediaControlKeyListener->IsStarted()) { + MEDIACONTROL_LOG("Failed to start the listener when entering fullscreen"); + } } + // Updating controller fullscreen state no matter the listener starts or not. BrowsingContext* bc = OwnerDoc()->GetBrowsingContext(); if (RefPtr updater = ContentMediaAgent::Get(bc)) { updater->NotifyMediaFullScreenState(bc->Id(), isInFullScreen); @@ -7919,7 +7921,16 @@ bool HTMLMediaElement::IsInFullScreen() const { return State().HasState(NS_EVENT_STATE_FULLSCREEN); } +bool HTMLMediaElement::IsPlayable() const { + return (mDecoder || mSrcStream) && !HasError(); +} + bool HTMLMediaElement::ShouldStartMediaControlKeyListener() const { + if (!IsPlayable()) { + MEDIACONTROL_LOG("Not start listener because media is not playable"); + return false; + } + if (IsBeingUsedInPictureInPictureMode()) { MEDIACONTROL_LOG("Start listener because of being used in PiP mode"); return true; @@ -7965,8 +7976,10 @@ void HTMLMediaElement::UpdateMediaControlAfterPictureInPictureModeChanged() { // When media enters PIP mode, we should ensure that the listener has been // started because we always want to control PIP video. StartMediaControlKeyListenerIfNeeded(); - MOZ_ASSERT(mMediaControlKeyListener->IsStarted(), - "Failed to start listener when entering PIP mode"); + if (!mMediaControlKeyListener->IsStarted()) { + MEDIACONTROL_LOG("Failed to start listener when entering PIP mode"); + } + // Updating controller PIP state no matter the listener starts or not. mMediaControlKeyListener->SetPictureInPictureModeEnabled(true); } else { mMediaControlKeyListener->SetPictureInPictureModeEnabled(false); diff --git a/dom/html/HTMLMediaElement.h b/dom/html/HTMLMediaElement.h index 82e6c2e53aa8..c941ff2f7fa3 100644 --- a/dom/html/HTMLMediaElement.h +++ b/dom/html/HTMLMediaElement.h @@ -1932,6 +1932,10 @@ class HTMLMediaElement : public nsGenericHTMLElement, MozPromiseRequestHolder mResumePlaybackRequest; + // Return true if we have already a decoder or a src stream and don't have any + // error. + bool IsPlayable() const; + // Return true if the media qualifies for being controlled by media control // keys. bool ShouldStartMediaControlKeyListener() const;