Merge pull request #914 from Stremio/fix/workaround-binge-watching-full-support
Some checks are pending
Build / build (push) Waiting to run

Shell: Fix binge watching flow
This commit is contained in:
Timothy Z. 2025-06-24 11:17:34 +03:00 committed by GitHub
commit ec1e098c99
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -115,17 +115,22 @@ const Player = ({ urlParams, queryParams }) => {
}, []);
const onEnded = React.useCallback(() => {
// here we need to explicitly check for isNavigating.current
// the ended event can be called multiple times by MPV inside Shell
if (isNavigating.current) {
return;
}
ended();
if (player.nextVideo !== null) {
onNextVideoRequested();
if (window.playerNextVideo !== null) {
nextVideo();
const deepLinks = window.playerNextVideo.deepLinks;
handleNextVideoNavigation(deepLinks);
} else {
window.history.back();
}
}, [player.nextVideo, onNextVideoRequested]);
}, []);
const onError = React.useCallback((error) => {
console.error('Player', error);
@ -405,6 +410,14 @@ const Player = ({ urlParams, queryParams }) => {
closeNextVideoPopup();
}
}
if (player.nextVideo) {
// This is a workaround for the fact that when we call onEnded nextVideo from the player is already set to null since core unloads the stream
// we explicitly set it to a global variable so we can access it in the onEnded function
// this is not a good solution but it works for now
window.playerNextVideo = player.nextVideo;
} else {
window.playerNextVideo = null;
}
}, [player.nextVideo, video.state.time, video.state.duration]);
React.useEffect(() => {
@ -447,6 +460,9 @@ const Player = ({ urlParams, queryParams }) => {
defaultSubtitlesSelected.current = false;
defaultAudioTrackSelected.current = false;
nextVideoPopupDismissed.current = false;
// we need a timeout here to make sure that previous page unloads and the new one loads
// avoiding race conditions and flickering
setTimeout(() => isNavigating.current = false, 1000);
}, [video.state.stream]);
React.useEffect(() => {