问题描述
我正在开发一个应用程序作为锻炼,具有同步用户选择的youtube视频的功能,为此,我正在使用ReactJs,Socket.io和React-player,但是当我进入同步部分时我有个问题。
我打算执行以下操作:视频的进度时间存储在useState中,如果用户是房间的所有者,并且此常数每隔1秒更新一次进度,那么在启动视频时,handleStartVideo函数为触发该事件,将导致该用户从会议室所有者那里收到视频时会发现的currentTime,但是,我的问题是:我怎么能告知要使用的currenTime是仅在已定义的常量中由房间的所有者和对于普通用户没有定义的值?可以通过socket.io发送?
const [videoCurrentTime,setVideoCurrentTime] = useState<[]>([]);
const reactRef = useRef(null);
function handleNumberProgress(numberProgress:number) {
if(userName === ownerRoom) {
setVideoCurrentTime(numberProgress);
}
}
function handleStartVideo() {
if(userName === ownerRoom) {
console.log("Você é o dono da sala");
} else {
reactRef.current?.seekTo(videoCurrentTime);
}
}
<ReactPlayer
url="https://www.youtube.com/watch?v=ysz5S6PUM-U"
ref={reactRef}
onStart={handleStartVideo}
progressInterval={1000}
onProgress={(e) => {handleNumberProgress(e.playedSeconds)}}
config={{
youtube: {
playerVars: {
showinfo: 1,autoplay: 1,}
},}}
/>
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)