Add poster option to JSMpegPlayer for displaying a snapshot of the camera feed

This commit is contained in:
Sergey Krashevich 2023-07-07 15:18:22 +03:00
parent 186e6a4a34
commit 46752970b7
No known key found for this signature in database
GPG Key ID: 625171324E7D3856

View File

@ -6,12 +6,13 @@ import JSMpeg from '@cycjimmy/jsmpeg-player';
export default function JSMpegPlayer({ camera, width, height }) {
const playerRef = useRef();
const url = `${baseUrl.replace(/^http/, 'ws')}live/jsmpeg/${camera}`;
const snapshot = `${baseUrl}api/${camera}/latest.jpg?h=${height}`;
useEffect(() => {
const video = new JSMpeg.VideoElement(
playerRef.current,
url,
{},
{poster: snapshot},
{protocols: [], audio: false, videoBufferSize: 1024*1024*4}
);
@ -29,7 +30,7 @@ export default function JSMpegPlayer({ camera, width, height }) {
return () => {
video.destroy();
};
}, [url]);
}, [snapshot, url]);
return (
<div ref={playerRef} class="jsmpeg" style={`max-height: ${height}px; max-width: ${width}px`} />