本文介绍了jwplayer-如何获得播放前的视频时长?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在jwplayer开始播放之前获取视频的时长.我尝试在onReady事件回调中调用getDuration(),但它返回-1.当我在onPlay事件回调中调用getDuration()时,我得到了正确的值.有什么想法吗?
I'm trying to get the duration of a video before the jwplayer starts playing. I tried calling getDuration () in the onReady event callback, but it returns -1. When I call getDuration () in the onPlay event callback, I get the correct value. Any ideas?
这是我的代码:
<video src="movie.mp4" id="video" width="800" height="600"></video>
<script type="text/javascript">
jwplayer ('video').setup ({
flashplayer: '/js/mediaplayer-5.10/player.swf',
width: 600,
height: 400,
events: {
onReady: function () {
var duration = this.getDuration();
alert ('ready, duration: ' + duration);
},
onPlay: function (state) {
alert ('play, duration: ' + this.getDuration());
}
}
});
</script>
推荐答案
这大约是我处理此问题的方式:
This is approximately how I have handled this problem:
var duration = 0;
jwplayer().onReady(function() {
if (duration == 0) {
// we don't have a duration yet, so start playing
jwplayer().play();
}
});
jwPlayer().onTime(function() {
if (duration == 0) {
// we don't have a duration, so it's playing so we can discover it...
duration = jwplayer().getDuration();
jwplayer().stop();
// do something with duration here
} else {
...
}
}
这篇关于jwplayer-如何获得播放前的视频时长?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!