Skip to content

Commit

Permalink
Ensure MSE onPlaying always gets called, even if loadeddata never fir…
Browse files Browse the repository at this point in the history
…es (#12271)

* Ensure MSE onPlaying always gets called, even if loadeddata never fires

* Call handleLoadedMetadata too if not playing yet
  • Loading branch information
hawkeye217 authored Jul 2, 2024
1 parent fe9a3c9 commit be9e606
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions web/src/components/player/MsePlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function MSEPlayer({
];

const visibilityCheck: boolean = !pip;
const [safariPlaying, setSafariPlaying] = useState(false);
const [isPlaying, setIsPlaying] = useState(false);

const [wsState, setWsState] = useState<number>(WebSocket.CLOSED);
const [connectTS, setConnectTS] = useState<number>(0);
Expand Down Expand Up @@ -124,16 +124,14 @@ function MSEPlayer({
setBufferTimeout(undefined);
}

if ((isSafari || isIOS) && safariPlaying) {
setSafariPlaying(false);
}
setIsPlaying(false);

if (wsRef.current) {
setWsState(WebSocket.CLOSED);
wsRef.current.close();
wsRef.current = null;
}
}, [bufferTimeout, safariPlaying]);
}, [bufferTimeout]);

const onOpen = () => {
setWsState(WebSocket.OPEN);
Expand Down Expand Up @@ -382,12 +380,14 @@ function MSEPlayer({
onLoadedData={() => {
handleLoadedMetadata?.();
onPlaying?.();
setIsPlaying(true);
}}
muted={!audioEnabled}
onPause={() => videoRef.current?.play()}
onProgress={() => {
if ((isSafari || isIOS) && !safariPlaying) {
setSafariPlaying(true);
if (!isPlaying) {
setIsPlaying(true);
handleLoadedMetadata?.();
onPlaying?.();
}
if (onError != undefined) {
Expand Down

0 comments on commit be9e606

Please sign in to comment.