Ensure MSE onPlaying always gets called, even if loadeddata never fires (#12271)

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

* Call handleLoadedMetadata too if not playing yet
This commit is contained in:
Josh Hawkins 2024-07-02 17:48:38 -05:00 committed by GitHub
parent fe9a3c9205
commit be9e606ae4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -45,7 +45,7 @@ function MSEPlayer({
]; ];
const visibilityCheck: boolean = !pip; const visibilityCheck: boolean = !pip;
const [safariPlaying, setSafariPlaying] = useState(false); const [isPlaying, setIsPlaying] = useState(false);
const [wsState, setWsState] = useState<number>(WebSocket.CLOSED); const [wsState, setWsState] = useState<number>(WebSocket.CLOSED);
const [connectTS, setConnectTS] = useState<number>(0); const [connectTS, setConnectTS] = useState<number>(0);
@ -124,16 +124,14 @@ function MSEPlayer({
setBufferTimeout(undefined); setBufferTimeout(undefined);
} }
if ((isSafari || isIOS) && safariPlaying) { setIsPlaying(false);
setSafariPlaying(false);
}
if (wsRef.current) { if (wsRef.current) {
setWsState(WebSocket.CLOSED); setWsState(WebSocket.CLOSED);
wsRef.current.close(); wsRef.current.close();
wsRef.current = null; wsRef.current = null;
} }
}, [bufferTimeout, safariPlaying]); }, [bufferTimeout]);
const onOpen = () => { const onOpen = () => {
setWsState(WebSocket.OPEN); setWsState(WebSocket.OPEN);
@ -382,12 +380,14 @@ function MSEPlayer({
onLoadedData={() => { onLoadedData={() => {
handleLoadedMetadata?.(); handleLoadedMetadata?.();
onPlaying?.(); onPlaying?.();
setIsPlaying(true);
}} }}
muted={!audioEnabled} muted={!audioEnabled}
onPause={() => videoRef.current?.play()} onPause={() => videoRef.current?.play()}
onProgress={() => { onProgress={() => {
if ((isSafari || isIOS) && !safariPlaying) { if (!isPlaying) {
setSafariPlaying(true); setIsPlaying(true);
handleLoadedMetadata?.();
onPlaying?.(); onPlaying?.();
} }
if (onError != undefined) { if (onError != undefined) {