More scene player bug fixes (#5379)

* Don't play video when seeking non-started video
* Set initial time on load instead of play
* Continue playing from current position when switching sources on error
* Remove unnecessary ref
This commit is contained in:
WithoutPants
2024-10-15 16:03:56 +11:00
committed by GitHub
parent 5283eb8ce3
commit 6d07ecf751
2 changed files with 8 additions and 19 deletions

View File

@@ -243,7 +243,6 @@ export const ScenePlayer: React.FC<IScenePlayerProps> = ({
const [fullscreen, setFullscreen] = useState(false);
const [showScrubber, setShowScrubber] = useState(false);
const initialTimestamp = useRef(-1);
const started = useRef(false);
const auto = useRef(false);
const interactiveReady = useRef(false);
@@ -457,20 +456,6 @@ export const ScenePlayer: React.FC<IScenePlayerProps> = ({
if (this.currentTime() >= 0.1) {
return;
}
if (initialTimestamp.current !== -1) {
this.currentTime(initialTimestamp.current);
initialTimestamp.current = -1;
}
}
function timeupdate(this: VideoJsPlayer) {
// fired when seeking
// check if we haven't started playing yet
// if so, start playing
if (!started.current) {
this.play();
}
}
function playing(this: VideoJsPlayer) {
@@ -493,14 +478,12 @@ export const ScenePlayer: React.FC<IScenePlayerProps> = ({
player.on("playing", playing);
player.on("loadstart", loadstart);
player.on("fullscreenchange", fullscreenchange);
player.on("timeupdate", timeupdate);
return () => {
player.off("canplay", canplay);
player.off("playing", playing);
player.off("loadstart", loadstart);
player.off("fullscreenchange", fullscreenchange);
player.off("timeupdate", timeupdate);
};
}, [getPlayer]);
@@ -675,7 +658,6 @@ export const ScenePlayer: React.FC<IScenePlayerProps> = ({
startPosition = resumeTime;
}
initialTimestamp.current = startPosition;
setTime(startPosition);
player.load();
@@ -683,6 +665,10 @@ export const ScenePlayer: React.FC<IScenePlayerProps> = ({
player.ready(() => {
player.vttThumbnails().src(scene.paths.vtt ?? null);
if (startPosition) {
player.currentTime(startPosition);
}
});
started.current = false;
@@ -811,7 +797,6 @@ export const ScenePlayer: React.FC<IScenePlayerProps> = ({
if (started.current) {
getPlayer()?.currentTime(seconds);
} else {
initialTimestamp.current = seconds;
setTime(seconds);
}
}

View File

@@ -196,8 +196,12 @@ class SourceSelectorPlugin extends videojs.getPlugin("plugin") {
console.log(`Trying next source in playlist: '${newSource.label}'`);
this.menu.setSelectedSource(newSource);
const currentTime = player.currentTime();
player.src(newSource);
player.load();
player.one("canplay", () => {
player.currentTime(currentTime);
});
player.play();
} else {
console.log("No more sources in playlist");