Feat: basic media control

Fixed dragging undefined tabs
This commit is contained in:
Slowlife01
2025-03-09 09:53:07 +07:00
parent 3df1973ac9
commit e6552c8dda
14 changed files with 638 additions and 3 deletions

View File

@@ -0,0 +1,27 @@
diff --git a/dom/chrome-webidl/MediaController.webidl b/dom/chrome-webidl/MediaController.webidl
index 20f416d1c3b41798e0f90bbac5db40ed2a4ab000..06cb4c847fcfba964eeb93089613e293dc10bd87 100644
--- a/dom/chrome-webidl/MediaController.webidl
+++ b/dom/chrome-webidl/MediaController.webidl
@@ -20,6 +20,12 @@ enum MediaControlKey {
"stop",
};
+dictionary MediaControllerPositionState {
+ required double duration;
+ required double playbackRate;
+ required double position;
+};
+
/**
* MediaController is used to control media playback for a tab, and each tab
* would only have one media controller, which can be accessed from the
@@ -36,6 +42,9 @@ interface MediaController : EventTarget {
[Throws]
MediaMetadataInit getMetadata();
+ [Throws]
+ MediaControllerPositionState getPositionState();
+
[Frozen, Cached, Pure]
readonly attribute sequence<MediaControlKey> supportedKeys;

View File

@@ -0,0 +1,30 @@
diff --git a/dom/media/mediacontrol/MediaController.cpp b/dom/media/mediacontrol/MediaController.cpp
index 3f08d24d4ed56bb72ed513ed602b2c8fa48afe7b..690d9abdb0ab8efc019dd606743b82504834faa0 100644
--- a/dom/media/mediacontrol/MediaController.cpp
+++ b/dom/media/mediacontrol/MediaController.cpp
@@ -51,6 +51,25 @@ void MediaController::GetSupportedKeys(
}
}
+void MediaController::GetPositionState(MediaControllerPositionState& aPositionState, ErrorResult& aRv) {
+ if (!IsActive() || mShutdown) {
+ LOG("Cannot get position state: controller is inactive or shut down");
+ aRv.Throw(NS_ERROR_NOT_AVAILABLE);
+ return;
+ }
+
+ Maybe<PositionState> currentPositionState = GetCurrentPositionState();
+ if (!currentPositionState) {
+ LOG("No position state available for controller %" PRId64, Id());
+ aRv.Throw(NS_ERROR_NOT_AVAILABLE);
+ return;
+ }
+
+ aPositionState.mDuration = currentPositionState->mDuration;
+ aPositionState.mPosition = currentPositionState->mLastReportedPlaybackPosition;
+ aPositionState.mPlaybackRate = currentPositionState->mPlaybackRate;
+}
+
void MediaController::GetMetadata(MediaMetadataInit& aMetadata,
ErrorResult& aRv) {
if (!IsActive() || mShutdown) {

View File

@@ -0,0 +1,12 @@
diff --git a/dom/media/mediacontrol/MediaController.h b/dom/media/mediacontrol/MediaController.h
index 8fec9c59e38bc24b9ff6d30ddbaebff67107bc76..5e7f3634f9edef48d6f96b4900f82a7ebbd730be 100644
--- a/dom/media/mediacontrol/MediaController.h
+++ b/dom/media/mediacontrol/MediaController.h
@@ -90,6 +90,7 @@ class MediaController final : public DOMEventTargetHelper,
JS::Handle<JSObject*> aGivenProto) override;
void GetSupportedKeys(nsTArray<MediaControlKey>& aRetVal) const;
void GetMetadata(MediaMetadataInit& aMetadata, ErrorResult& aRv);
+ void GetPositionState(MediaControllerPositionState& aPositionState, ErrorResult& aRv);
IMPL_EVENT_HANDLER(activated);
IMPL_EVENT_HANDLER(deactivated);
IMPL_EVENT_HANDLER(metadatachange);