reactjs - 如何在 React 应用程序中将 JWPlayer 或 Plyr.io 用于视频播放器?
问题描述
我创建一个组件说“视频播放器”并使用来自 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中的视频播放器有什么解决方案吗?
解决方案
我认为你正在寻找它已经在这个包中制作:https ://www.npmjs.com/package/react-plyr
应该给你你正在寻找的结果。
推荐阅读
- google-sheets - Google表格countif:排除多个值并计算其他所有值
- apt - 运行命令 apt-get update 时在 openvpn repo 中出现错误
- delphi - Delphi Rio 中的 TVirtualImageList 和表单继承
- javascript - 在 HTML 页面中播放 .m4a 音频文件不起作用
- r - 在 R 中用我自己的回归模型计算 R 平方
- python - pipenv 在 vs 代码中设置虚拟环境的路径
- python-3.x - 如何从 Pandas 中的 excel 文件中排除页眉和页脚
- javascript - 如何过滤编辑的数据,它应该以角度显示选择要编辑的数据
- jquery-ui - Jquery datepicker 中 .Remove() 和 .Destroy() 的区别
- python - 如何更准确地定义跟随颜色的 HSV 范围?