diff --git a/web/src/components/player/MsePlayer.tsx b/web/src/components/player/MsePlayer.tsx index 0300557de..e4ed4393e 100644 --- a/web/src/components/player/MsePlayer.tsx +++ b/web/src/components/player/MsePlayer.tsx @@ -46,7 +46,6 @@ function MSEPlayer({ const visibilityCheck: boolean = !pip; const [isPlaying, setIsPlaying] = useState(false); - const playTimeoutRef = useRef(null); const [wsState, setWsState] = useState(WebSocket.CLOSED); const [connectTS, setConnectTS] = useState(0); @@ -298,6 +297,11 @@ function MSEPlayer({ }; }; + const getBufferedTime = (video: HTMLVideoElement | null) => { + if (!video || video.buffered.length === 0) return 0; + return video.buffered.end(video.buffered.length - 1) - video.currentTime; + }; + useEffect(() => { if (!playbackEnabled) { return; @@ -380,21 +384,22 @@ function MSEPlayer({ preload="auto" onLoadedData={() => { handleLoadedMetadata?.(); - if (playTimeoutRef.current) { - clearTimeout(playTimeoutRef.current); - playTimeoutRef.current = null; - } onPlaying?.(); setIsPlaying(true); }} muted={!audioEnabled} onPause={() => videoRef.current?.play()} onProgress={() => { - if (!isPlaying && !playTimeoutRef.current && playbackEnabled) { - playTimeoutRef.current = setTimeout(() => { - setIsPlaying(true); - onPlaying?.(); - }, 7000); + // if we have > 3 seconds of buffered data and we're still not playing, + // something might be wrong - maybe codec issue, no audio, etc + // so mark the player as playing so that error handlers will fire + if ( + !isPlaying && + playbackEnabled && + getBufferedTime(videoRef.current) > 3 + ) { + setIsPlaying(true); + onPlaying?.(); } if (onError != undefined) { if (videoRef.current?.paused) { diff --git a/web/src/views/live/LiveCameraView.tsx b/web/src/views/live/LiveCameraView.tsx index 65581d502..f148f01ee 100644 --- a/web/src/views/live/LiveCameraView.tsx +++ b/web/src/views/live/LiveCameraView.tsx @@ -399,7 +399,7 @@ export default function LiveCameraView({ onClick={() => setMic(!mic)} /> )} - {supportsAudioOutput && ( + {supportsAudioOutput && preferredLiveMode != "jsmpeg" && (