Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Player fixes #12033

Merged
merged 1 commit into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Memoize onPlaying and only instantiate one jsmpeg player
  • Loading branch information
hawkeye217 committed Jun 17, 2024
commit abaf1899a970c41dcc2bfe7bf8c8a6b9b4cafc70
11 changes: 7 additions & 4 deletions web/src/components/player/JSMpegPlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export default function JSMpegPlayer({
const playerRef = useRef<HTMLDivElement | null>(null);
const videoRef = useRef(null);
const internalContainerRef = useRef<HTMLDivElement | null>(null);
const onPlayingRef = useRef(onPlaying);

const selectedContainerRef = useMemo(
() => containerRef ?? internalContainerRef,
Expand Down Expand Up @@ -83,7 +84,11 @@ export default function JSMpegPlayer({
const uniqueId = useId();

useEffect(() => {
if (!playerRef.current) {
onPlayingRef.current = onPlaying;
}, [onPlaying]);

useEffect(() => {
if (!playerRef.current || videoRef.current) {
return;
}

Expand All @@ -96,12 +101,10 @@ export default function JSMpegPlayer({
audio: false,
videoBufferSize: 1024 * 1024 * 4,
onPlay: () => {
onPlaying?.();
onPlayingRef.current?.();
},
},
);
// we know that these deps are correct
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [url, uniqueId]);

return (
Expand Down
12 changes: 8 additions & 4 deletions web/src/components/player/LivePlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import WebRtcPlayer from "./WebRTCPlayer";
import { CameraConfig } from "@/types/frigateConfig";
import AutoUpdatingCameraImage from "../camera/AutoUpdatingCameraImage";
import ActivityIndicator from "../indicators/activity-indicator";
import { useEffect, useMemo, useState } from "react";
import { useCallback, useEffect, useMemo, useState } from "react";
import MSEPlayer from "./MsePlayer";
import JSMpegPlayer from "./JSMpegPlayer";
import { MdCircle } from "react-icons/md";
Expand Down Expand Up @@ -125,6 +125,10 @@ export default function LivePlayer({
setLiveReady(false);
}, [preferredLiveMode]);

const playerIsPlaying = useCallback(() => {
setLiveReady(true);
}, []);

if (!cameraConfig) {
return <ActivityIndicator />;
}
Expand All @@ -141,7 +145,7 @@ export default function LivePlayer({
audioEnabled={playAudio}
microphoneEnabled={micEnabled}
iOSCompatFullScreen={iOSCompatFullScreen}
onPlaying={() => setLiveReady(true)}
onPlaying={playerIsPlaying}
pip={pip}
onError={onError}
/>
Expand All @@ -154,7 +158,7 @@ export default function LivePlayer({
camera={cameraConfig.live.stream_name}
playbackEnabled={cameraActive}
audioEnabled={playAudio}
onPlaying={() => setLiveReady(true)}
onPlaying={playerIsPlaying}
pip={pip}
setFullResolution={setFullResolution}
onError={onError}
Expand All @@ -177,7 +181,7 @@ export default function LivePlayer({
width={cameraConfig.detect.width}
height={cameraConfig.detect.height}
containerRef={containerRef}
onPlaying={() => setLiveReady(true)}
onPlaying={playerIsPlaying}
/>
);
} else {
Expand Down