2014-08-29 85 views
0

我發現這個similar question here,但是答案在我的情況下不起作用。如何監聽HTML5視頻停止在jQuery中播放?

我的jsfiddle:http://jsfiddle.net/leongaban/yvne6fnt/

HTML

<div style="position: fixed; top: 0; width: 100%; height: 100%; z-index: -1;"> 
<video id="hero_video" controls="" autoplay="autoplay" preload poster="http://media.w3.org/2010/05/sintel/poster.png" style="width:100%; height:100%"> 
    <source id="mp4" src="http://leongaban.com/v6/videos/clouds.mp4" type="video/mp4"> 
    <source id="webm" src="http://leongaban.com/v6/videos/clouds.webm" type="video/webm"> 
    <source id="ogv" src="http://leongaban.com/v6/videos/clouds.ogv" type="video/ogg"> 
    <p>Your user agent does not support the HTML5 Video element.</p> 
</video> 

JS

$("#hero_video").bind('stop', function(e) { 
    console.log('stopped'); 
    alert('stopped'); 
}, true); 

/* 
$("video").bind('stop', function(e) { 
    console.log('stopped'); 
    alert('stopped'); 
}, true); 
*/ 

回答

1

如果您從您的函數中第三個參數此作品:

$("#hero_video").bind('stop', function(e) { 
    console.log('stopped'); 
    alert('stopped'); 
}); 

請注意,這隻會在開始處和視頻時觸發。如果你也想觸發暫停的情況下,你必須還包括暫停事件:

$("#hero_video").bind('stop pause', function(e) { 
    console.log('stopped'); 
    alert('stopped'); 
}); 

的jsfiddle:http://jsfiddle.net/yvne6fnt/8/

不知道爲什麼這個工程雖然,因爲對於這樣的說法默認爲truehttp://api.jquery.com/bind/

+0

啊甜美的感謝! – 2014-08-29 14:42:19

+0

哦,我注意到,我不得不使用'stop pause'來代替只是因爲某種原因找到事件'stop' – 2014-08-29 14:55:11

+0

是的,停止只在視頻結束時觸發。 – 2014-08-29 14:56:26