Bug 1887128 - Guess position state from media elements. r=alwu
Differential Revision: https://phabricator.services.mozilla.com/D204691
This commit is contained in:
@@ -318,7 +318,7 @@ class HTMLMediaElement::MediaControlKeyListener final
|
||||
|
||||
MOZ_INIT_OUTSIDE_CTOR explicit MediaControlKeyListener(
|
||||
HTMLMediaElement* aElement)
|
||||
: mElement(aElement) {
|
||||
: mElement(aElement), mElementId(nsID::GenerateUUID()) {
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
MOZ_ASSERT(aElement);
|
||||
}
|
||||
@@ -411,6 +411,33 @@ class HTMLMediaElement::MediaControlKeyListener final
|
||||
}
|
||||
}
|
||||
|
||||
void NotifyMediaPositionState() {
|
||||
if (!IsStarted()) {
|
||||
return;
|
||||
}
|
||||
|
||||
MOZ_ASSERT(mControlAgent);
|
||||
auto* owner = Owner();
|
||||
PositionState state(owner->Duration(), owner->PlaybackRate(),
|
||||
owner->CurrentTime(), TimeStamp::Now());
|
||||
MEDIACONTROL_LOG(
|
||||
"Notify media position state (duration=%f, playbackRate=%f, "
|
||||
"position=%f)",
|
||||
state.mDuration, state.mPlaybackRate,
|
||||
state.mLastReportedPlaybackPosition);
|
||||
mControlAgent->UpdateGuessedPositionState(mOwnerBrowsingContextId,
|
||||
mElementId, Some(state));
|
||||
}
|
||||
|
||||
void Shutdown() {
|
||||
StopIfNeeded();
|
||||
if (!mControlAgent) {
|
||||
return;
|
||||
}
|
||||
mControlAgent->UpdateGuessedPositionState(mOwnerBrowsingContextId,
|
||||
mElementId, Nothing());
|
||||
}
|
||||
|
||||
// This method can be called before the listener starts, which would cache
|
||||
// the audible state and update after the listener starts.
|
||||
void UpdateMediaAudibleState(bool aIsOwnerAudible) {
|
||||
@@ -543,6 +570,10 @@ class HTMLMediaElement::MediaControlKeyListener final
|
||||
MOZ_ASSERT(mState != aState, "Should not notify same state again!");
|
||||
mState = aState;
|
||||
mControlAgent->NotifyMediaPlaybackChanged(mOwnerBrowsingContextId, mState);
|
||||
|
||||
if (aState == MediaPlaybackState::ePlayed) {
|
||||
NotifyMediaPositionState();
|
||||
}
|
||||
}
|
||||
|
||||
void NotifyAudibleStateChanged(MediaAudibleState aState) {
|
||||
@@ -557,6 +588,7 @@ class HTMLMediaElement::MediaControlKeyListener final
|
||||
bool mIsPictureInPictureEnabled = false;
|
||||
bool mIsOwnerAudible = false;
|
||||
MOZ_INIT_OUTSIDE_CTOR uint64_t mOwnerBrowsingContextId;
|
||||
const nsID mElementId;
|
||||
};
|
||||
|
||||
class HTMLMediaElement::MediaStreamTrackListener
|
||||
@@ -2065,7 +2097,7 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(HTMLMediaElement,
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mSeekDOMPromise)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mSetMediaKeysDOMPromise)
|
||||
if (tmp->mMediaControlKeyListener) {
|
||||
tmp->mMediaControlKeyListener->StopIfNeeded();
|
||||
tmp->mMediaControlKeyListener->Shutdown();
|
||||
}
|
||||
if (tmp->mEventBlocker) {
|
||||
tmp->mEventBlocker->Shutdown();
|
||||
@@ -3384,6 +3416,8 @@ void HTMLMediaElement::Seek(double aTime, SeekTarget::Type aSeekType,
|
||||
|
||||
// We changed whether we're seeking so we need to AddRemoveSelfReference.
|
||||
AddRemoveSelfReference();
|
||||
|
||||
mMediaControlKeyListener->NotifyMediaPositionState();
|
||||
}
|
||||
|
||||
double HTMLMediaElement::Duration() const {
|
||||
@@ -6871,6 +6905,7 @@ void HTMLMediaElement::SetPlaybackRate(double aPlaybackRate, ErrorResult& aRv) {
|
||||
mDecoder->SetPlaybackRate(ClampPlaybackRate(mPlaybackRate));
|
||||
}
|
||||
DispatchAsyncEvent(u"ratechange"_ns);
|
||||
mMediaControlKeyListener->NotifyMediaPositionState();
|
||||
}
|
||||
|
||||
void HTMLMediaElement::SetPreservesPitch(bool aPreservesPitch) {
|
||||
|
||||
Reference in New Issue
Block a user