feat(UI): Add fastSeek support for MediaSession seekTo (#9884)

This commit is contained in:
Álvaro Velad Galván
2026-03-24 12:02:34 +01:00
committed by GitHub
parent a62e87b351
commit f7f28bec4a
4 changed files with 43 additions and 10 deletions
+17
View File
@@ -0,0 +1,17 @@
/*! @license
* Shaka Player
* Copyright 2016 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @fileoverview Externs for HTMLMediaElement.fastSeek
* @externs
*/
/**
* Seeks to a given time quickly.
* @param {number} time
*/
HTMLMediaElement.prototype.fastSeek = function(time) {};
+13 -2
View File
@@ -13,6 +13,18 @@
*/
/**
* @typedef {{
* action: string,
* seekOffset: (number|undefined),
* seekTime: (number|undefined),
* fastSeek: (boolean|undefined),
* enterPictureInPictureReason: (string|undefined)
* }}
*/
var MediaSessionActionDetails;
const MediaMetadata = class {
constructor(options) {
/** @type {string} */
@@ -44,8 +56,7 @@ const MediaSession = class {
this.type = type;
/**
* @type {!function(!{action: string, seekOffset: ?number,
* seekTime: ?number})}
* @type {!function(!MediaSessionActionDetails)}
*/
this.callback = callback;
}
+10 -5
View File
@@ -2357,13 +2357,17 @@ shaka.ui.Controls = class extends shaka.util.FakeEventTarget {
* Update the video's current time based on the keyboard operations.
*
* @param {number} currentTime
* @param {boolean=} fastSeek
* @private
*/
seek_(currentTime) {
seek_(currentTime, fastSeek = false) {
goog.asserts.assert(
this.seekBar_, 'Caller of seek_ must check for seekBar_ first!');
this.video_.currentTime = currentTime;
if (fastSeek && 'fastSeek' in this.video_) {
this.video_.fastSeek(currentTime);
} else {
this.video_.currentTime = currentTime;
}
this.updateTimeAndSeekRange_();
}
@@ -2376,9 +2380,10 @@ shaka.ui.Controls = class extends shaka.util.FakeEventTarget {
/**
* @param {number} value
* @param {boolean} fastSeek
*/
seekTo(value) {
this.seek_(value);
seekTo(value, fastSeek) {
this.seek_(value, fastSeek);
}
/**
+3 -3
View File
@@ -273,8 +273,7 @@ shaka.ui.MediaSession = class {
}
/**
* @param {!{action: string, seekOffset: ?number,
* seekTime: ?number}} details
* @param {!MediaSessionActionDetails} details
* @export
*/
commonActionHandler(details) {
@@ -310,8 +309,9 @@ shaka.ui.MediaSession = class {
break;
}
if (!ad || !ad.isLinear()) {
const fastSeek = details.fastSeek || false;
this.controls_.seekTo(
this.player_.seekRange().start + details.seekTime);
this.player_.seekRange().start + details.seekTime, fastSeek);
}
break;
case 'stop':