【发布时间】:2017-05-03 21:09:59
【问题描述】:
我正在使用 videoJs 将视频加载到管理员中 平台内置反应。我在这里设置播放器:
else if (contentSource == 'arclight'){
var options = {
height:'216',
sources :[{
//src: this.state.video.url,
// type: 'video/mp4'
}]
}
var player = videojs('player',options,function onPlayerReady() {
videojs.log('Your player is ready!');
})
this.setState({
player:player,content: contentSource
});
}
我的视频显示在这个标签中:
<video id="player" class="player"
className={`video-js vjs-default-skin vjs-big-play-centered
${styles.vjs}`}
controls preload= "auto" data-
setup='{"example_option":true}'>
<source src={this.state.video.url} type= "video/mp4" />
<p className="vjs-no-js">
To view this video please enable JavaScript, and consider
upgrading to a web browser that
<a href= "http://videojs.com/html5-video-support"
target="_blank"> supports HTML5 video </a>
</p>
</video>
最后我正在尝试获取以这种方法播放的视频的当前时间
handleCurrentButton(inputId, event){
event.preventDefault();
var timeMark =0;
if(this.state.content == 'vimeo'){
this.state.player.getCurrentTime().then(function(seconds){console.log(seconds)
timeMark=seconds;
VideosActions.updateVideoAttribute(inputId, timeMark);
}).catch(function(error){
});
}
else if(this.state.content == 'youtube') {
timeMark = Math.round(this.state.player.getCurrentTime());
VideosActions.updateVideoAttribute(inputId, timeMark);
}
else {
// timeMark = this.state.player.currentTime();
console.log(this.state.player.currentTime())
VideosActions.updateVideoAttribute(inputId, timeMark);
}
}
问题是 player.currentTime() 调用总是返回 0。另外两个用于 Vimeo 和 Youtube 的 getCurrentTime 工作正常。这背后的原因是什么?我试图围绕这个问题提供足够的背景信息,以便您能够弄清楚。 提前感谢您的帮助!
【问题讨论】:
标签: javascript reactjs video.js