我正在使用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&#39; s工作正常。这背后的原因是什么?我试图给出足够的关于这个问题的背景,以便你能够弄明白。 感谢您的帮助!
答案 0 :(得分:1)
问题是getCurrentTime()返回一个promise,所以你需要访问promise作为对Promise .then()
函数的回调来解决的时间值。
else {
this.state.player.currentTime().then(function(seconds){
console.log(seconds)
timeMark=seconds;
VideosActions.updateVideoAttribute(inputId, timeMark);
});
}
答案 1 :(得分:0)
请确保您的服务器在视频HTTP请求上返回206响应,否则播放器将无法很好地处理搜索。