2014-10-16 36 views
0

我有一些第三方库和jQuery现在使用Javascript我需要检测是否有任何视频正在播放并以事件监听器结束。Javascript - 如何检查电影是否完成?同时使用jQuery和其他第三方库?

我尝试以下,但它不工作:

$(document).ready(function() { 
    if(InitialiseDocReadyScripts()) { 
     console.log('Initialised Document Ready Scripts Successfully'); 
    } else { 
     console.log('Failed to Initialise Document Ready Scripts'); 
    } 

    var play_video = document.getElementById('mediaplayer'); 
    play_video.onended = function(e) { 
    console.log('>>> Playing finished: ', e); 
    }; 

}); 
+0

_ “一些第三方库” _,你能解释一下?它是公开的,所以我们可以看看文档? – blex 2014-10-16 17:41:16

回答

1

检查当前的播放时间是==到视频的长度。

play_video.onended = function(e) { 
    if(this.currentTime == this.duration) { 
     console.log('video end'); 
    } 
}; 

currentTimeduration是HTML5视频的属性:http://www.w3schools.com/tags/ref_av_dom.asp