【发布时间】:2022-01-23 06:38:13
【问题描述】:
我正在播放 Youtube 视频。一旦输入了某些内容,API 服务器就会回复一个 URL,该 URL 在与 Youtube 相同的播放器中播放。 API 的视频结束后如何返回 YouTube 视频?
播放器视频代码(Typescript)如下所示,由videoUrlProp 提供,该状态处理来自父组件的 URL 响应。
const Player: React.FC<IProps> = ({
onProgress,
videoUrlProp,
}:
IProps) => {
// Don't mind this segment.
const { playerRef, isPlaying } = useStore(
(state) => ({ playerRef: state.playerRef, isPlaying: state.isPlaying }),
shallow
);
// We check if the source is the original. This is used to resize the player.
const isOriginalVideo = videoUrlProp.includes("youtube");
return (
<div className="player">
<ReactPlayer
url={videoUrlProp}
controls={true}
onProgress={onProgress}
width={isOriginalVideo ? "100%" : "70%"}
height={isOriginalVideo ? "100%" : "100%"}
className="react-player"
ref={playerRef}
playing={isPlaying}
/>
</div>
);
};
export default Player;
我正在为播放器使用react-player;这就是在父组件中声明状态的方式:
const [videoUrl, setVideoUrl] = useState(
"https://www.youtube.com/watch?v=something"
);
欢迎任何帮助。谢谢!
*编辑:我对 stackoverflow 的提问还是有点陌生,如果我遗漏了一些数据或者我是否应该以不同的方式写下来,请务必告诉我!泰! :)
【问题讨论】:
标签: javascript reactjs typescript react-hooks react-player