seek to 0 when revealing

This commit is contained in:
Thomas Ruoff
2020-11-29 00:28:46 +01:00
parent 0e063abc24
commit 93ab6a1699

View File

@@ -10,12 +10,12 @@ let player;
const Player = ({ hidden }) => { const Player = ({ hidden }) => {
const [playerState, setPlayerState] = useState(-1); const [playerState, setPlayerState] = useState(-1);
const { openSong } = useContext(AppContext); const { openSong: { id, startSeconds = 0, endSeconds = 0 } } = useContext(AppContext);
const onPause = () => player && player.pauseVideo(); const onPause = () => player && player.pauseVideo();
const onPlay = () => player && player.playVideo(); const onPlay = () => player && player.playVideo();
const onRestart = () => { const onRestart = () => {
player && player.seekTo(openSong.startSeconds || 0); player && player.seekTo(hidden ? startSeconds : 0);
player && [PAUSED, ENDED].includes(playerState) && player.playVideo(); player && [PAUSED, ENDED].includes(playerState) && player.playVideo();
}; };
@@ -29,9 +29,9 @@ const Player = ({ hidden }) => {
}); });
player.on("stateChange", setState); player.on("stateChange", setState);
player.loadVideoById({ player.loadVideoById({
videoId: openSong.id, videoId: id,
startSeconds: openSong.startSeconds, startSeconds: hidden ? startSeconds : 0,
endSeconds: openSong.endSeconds endSeconds: hidden ? endSeconds : undefined,
}); });
return () => { return () => {