您的位置:首页 > 其它

利用jwplayer的API实现播放定时弹出框效果

2015-04-10 19:44 483 查看
最近写的javaWeb涉及到了视频这块,用的是jwplayer,需要实现一个播放到某一进度视频自动暂停平且弹出一个框这样的功能。这需要找到一个类似于定时中断执行的函数可以实现不断的检测播放进度。在网上找了一下发现jwplayer的中文资料非常少,于是只好去翻官网提供的API。

最终还是找到了需要的API,以下是该函数的原文。

onTime(callback)

While the player is playing, this event is fired as the playback position gets updated. This may occur as frequently as 10 times per second. Event attributes:

duration (Number): Duration of the current item in seconds.

position (Number): Playback position in seconds.

Note that seeking for progressive downloads in Flash mode only works within the already downloaded portion. When seeking beyond that section, the video seeks to the last downloaded frame.
This issue is not present for HTML5, so should only be relevant for IE8.

说明:这个函数可以随着视频帧的更新而触发,时间间隔小于十分之一秒。

用法示例:

var pausePoint=30;
jwplayer("player").onTime(function (){
if (jwplayer("myElement").getState() === "PLAYING" && jwplayer("myElement").getPosition()>pausePoint) {
jwplayer("myElement").pause(true);
alert("Hi!");
jwplayer("myElement").play(true);
}
});
作用:在视频播放的第30秒暂停视频并且弹出框。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: