зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1779454 - Fix Netflix wrapper to allow scrubbing. r=pip-reviewers,mhowell
Differential Revision: https://phabricator.services.mozilla.com/D166403
This commit is contained in:
Родитель
5b55c170dc
Коммит
2e684db116
|
@ -17,11 +17,23 @@ class PictureInPictureVideoWrapper {
|
||||||
}
|
}
|
||||||
this.player = netflixPlayerAPI.getVideoPlayerBySessionId(sessionId);
|
this.player = netflixPlayerAPI.getVideoPlayerBySessionId(sessionId);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* The Netflix player returns the current time in milliseconds so we convert
|
||||||
|
* to seconds before returning.
|
||||||
|
* @param {HTMLVideoElement} video The original video element
|
||||||
|
* @returns {Number} The current time in seconds
|
||||||
|
*/
|
||||||
getCurrentTime(video) {
|
getCurrentTime(video) {
|
||||||
return this.player.getCurrentTime();
|
return this.player.getCurrentTime() / 1000;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* The Netflix player returns the duration in milliseconds so we convert to
|
||||||
|
* seconds before returning.
|
||||||
|
* @param {HTMLVideoElement} video The original video element
|
||||||
|
* @returns {Number} The duration in seconds
|
||||||
|
*/
|
||||||
getDuration(video) {
|
getDuration(video) {
|
||||||
return this.player.getDuration();
|
return this.player.getDuration() / 1000;
|
||||||
}
|
}
|
||||||
play() {
|
play() {
|
||||||
this.player.play();
|
this.player.play();
|
||||||
|
@ -53,29 +65,13 @@ class PictureInPictureVideoWrapper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the current time of the video in milliseconds.
|
||||||
|
* @param {HTMLVideoElement} video The original video element
|
||||||
|
* @param {Number} position The new time in seconds
|
||||||
|
*/
|
||||||
setCurrentTime(video, position) {
|
setCurrentTime(video, position) {
|
||||||
let oldTime = this.player.getCurrentTime();
|
this.player.seek(position * 1000);
|
||||||
let duration = this.player.getDuration();
|
|
||||||
let isHome = position == 0;
|
|
||||||
let isEnd = position >= duration;
|
|
||||||
// Read pipChild's expected seek result to determine if we want
|
|
||||||
// to move forward/backwards, or go to the start/end
|
|
||||||
let seekDirection = position - oldTime;
|
|
||||||
// But ignore pipChild's proposed seek forward/backward time for a better viewing
|
|
||||||
// experience. 10 seconds (10000ms) seems to be the best value for compatibility.
|
|
||||||
// The new currentTime will not always be 10 seconds forward/backward though, since Netflix
|
|
||||||
// adjusts the new currentTime when seek() is called, according to the current timestamp.
|
|
||||||
let seekTimeMS = 10000;
|
|
||||||
let newTime = 0;
|
|
||||||
|
|
||||||
if (isHome || isEnd) {
|
|
||||||
newTime = position;
|
|
||||||
} else if (seekDirection < 0) {
|
|
||||||
newTime = Math.max(oldTime - seekTimeMS, 0);
|
|
||||||
} else if (seekDirection > 0) {
|
|
||||||
newTime = Math.min(oldTime + seekTimeMS, duration);
|
|
||||||
}
|
|
||||||
this.player.seek(newTime);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче