【发布时间】:2021-05-25 11:47:31
【问题描述】:
我正在使用 react-player https://github.com/cookpete/react-player 播放我的视频。我的问题是,如何在播放选定视频时暂停其他视频?
const videoRef = useRef();
const updateVideoHandler = async (videoId, videoTitle) => {
setSelectedVideoId(videoId);
if (!selectedVideoId) {
videoRef?.current?.player?.player?.onPause();
}
};
<ReactPlayer
ref={videoRef}
onPlay={() => updateVideoHandler(video.id, video.title)}
playsinline={true}
playing={true}
controls={true}
url={video?.url}
width="100%"
height="100%"
playIcon={
<div
className="play-icon"
role="button"
tabIndex={0}
style={{ outline: "none" }}
>
{" "}
<img src="/images/play.png" alt="" />
</div>
}
light={video?.pic}
/>;
【问题讨论】:
-
你可以试试
useRef
标签: javascript reactjs react-hooks react-player