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

This commit is contained in:
Josh Hawkins 2024-07-02 15:24:18 -05:00
parent fe9a3c9205
commit 88693c19e5

View File

@ -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);
@ -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);
@ -382,12 +380,13 @@ function MSEPlayer({
onLoadedData={() => {
handleLoadedMetadata?.();
onPlaying?.();
setIsPlaying(true);
}}
muted={!audioEnabled}
onPause={() => videoRef.current?.play()}
onProgress={() => {
if ((isSafari || isIOS) && !safariPlaying) {
setSafariPlaying(true);
if (!isPlaying) {
setIsPlaying(true);
onPlaying?.();
}
if (onError != undefined) {