mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-12 22:25:24 +03:00
Use buffered time instead of timeout
This commit is contained in:
parent
6cb90e2ebe
commit
47dafca777
@ -46,7 +46,6 @@ function MSEPlayer({
|
||||
|
||||
const visibilityCheck: boolean = !pip;
|
||||
const [isPlaying, setIsPlaying] = useState(false);
|
||||
const playTimeoutRef = useRef<NodeJS.Timeout | null>(null);
|
||||
|
||||
const [wsState, setWsState] = useState<number>(WebSocket.CLOSED);
|
||||
const [connectTS, setConnectTS] = useState<number>(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(() => {
|
||||
// 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?.();
|
||||
}, 7000);
|
||||
}
|
||||
if (onError != undefined) {
|
||||
if (videoRef.current?.paused) {
|
||||
|
||||
@ -399,7 +399,7 @@ export default function LiveCameraView({
|
||||
onClick={() => setMic(!mic)}
|
||||
/>
|
||||
)}
|
||||
{supportsAudioOutput && (
|
||||
{supportsAudioOutput && preferredLiveMode != "jsmpeg" && (
|
||||
<CameraFeatureToggle
|
||||
className="p-2 md:p-0"
|
||||
variant={fullscreen ? "overlay" : "primary"}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user