我创建一个组件,例如“ Video Player”,然后使用Plyr.io中的播放器。创建用于使用handleVideoPlayer初始化的句柄。装有handlePlyrScript的Plyr脚本。
这是我的代码:
const VideoPlayer = (props) => {
return(
<div className={styles.videoSection}>
<div className={styles.videoResponsive}>
<video poster={props.video.poster} id="player" playsInline controls>
<source src={props.video.source} type="video/mp4" />
</video>
</div>
</div>
);
}
class PlayerPage extends Component {
state = {
currentEpisode : {},
allPlayList : [],
}
// load Plyr script from cdn
handlePlyrScript = () => {
const plyrscript = document.createElement('script');
plyrscript.src = 'https://cdn.plyr.io/3.5.2/plyr.polyfilled.js';
document.body.appendChild(plyrscript);
}
// handle Video Player
handleVideoPlayer = () => {
setTimeout(() => {
const player = new Plyr('#player')
}, 500)
}
componentDidMount = () => {
console.log(this);
if(typeof(this.props.location.state) !== "undefined"){
let play_data = this.props.location.state;
this.setState({
currentEpisode : play_data
})
} else {
console.log("nothing...")
}
// call the Plyr init video tag with #player
this.handlePlyrScript()
this.handleVideoPlayer()
}
render(){
return(
<div className={style.playerPageSection}>
<div className={style.videoWrapper}>
<div className={style.videoRow}>
<div className={style.videoLeft}>
<VideoPlayer video={this.state.currentEpisode} />
</div>
<div className={style.videoRight}>
</div>
</div>
</div>
</div>
);
}
}
export default PlayerPage;
但是结果并未显示具有Plyr风格的视频(该视频就像带有标签的通用播放器一样。)
在React APP中可以使用有关视频播放器的任何解决方案吗?