【发布时间】:2021-10-12 16:58:53
【问题描述】:
嘿,我试图让视频播放器做出反应,并想制作自己的控件,但我遇到了一个问题。handlePlay 是一个 OnClick 函数,应该播放或暂停视频。 isPlaying 是跟踪用户命令的状态(isPlaying 初始化为 true),但即使状态更新,视频也不会暂停。有人可以帮忙吗
谢谢
class Video extends React.Component {
constructor(...args) {
super(...args);
const video = document.createElement("video");
video.src = Vid;
video.type = "video/mp4";
this.state = {
video: video,
timestamps: [],
isPlaying: true,
};
video.addEventListener("canplay", () => {
if (this.state.isPlaying === true) {
console.log("play");
video.play();
//this.image.getLayer().batchDraw();
// this.requestUpdate();
} else {
console.log("pause");
video.pause();
//this.image.getLayer().batchDraw();
//this.requestUpdate();
}
});
}
handlePlay = () => {
if (this.state.isPlaying === true) {
this.setState({
isPlaying: false,
});
} else {
this.setState({
isPlaying: true,
});
}
};
【问题讨论】:
标签: javascript reactjs html5-video