// 摄像头
const videoEle = useRef(null);
const videoEleAdd = useRef<any>();
useEffect(() => {
if (rightTopBindData) {
let value = `rtsp://${rightTopBindData?.enterCamera.username}:${rightTopBindData?.enterCamera.password}@${rightTopBindData?.enterCamera.host}:${rightTopBindData?.enterCamera.rtspPort}/Streaming/Channels/101`;
if (videoEleEnter.current && value) {
videoEleAddEnter.current = new WebRtcStreamerxiaoxujs(
videoEleEnter.current!,
"http://localhost:8000"
);
videoEleAddEnter.current.connect(value);
}
return () => {
if (videoEleAddEnter.current) {
videoEleAddEnter.current.disconnect();
}
};
}
}, [rightTopBindData]);
其中 rightTopBindData 是后端返回字段,用来拼接请求地址, value 为请求拼接地址.
// html
<video
ref={videoEleEnter}
style={{ width: "100%", height: "100%" }}
id="video"
controls
muted
preload="auto"
></video>
本文介绍了一种使用React Hooks和WebRtcStreamerxiaoxujs库来实现从RTSP源加载并播放视频流的方法。通过解析后端返回的数据,动态创建视频元素并连接到指定的RTSP地址。
2306

被折叠的 条评论
为什么被折叠?



