[英]Fire function when HTML5 video seeks/plays
我正在嘗試使用每2分鍾失效的鏈接流式傳輸視頻。
基本上,我使用此函數替換URL,並且效果很好:
function test(){
var videoFile = 'new.mp4';
var $video = $('#m video');
var curtime = $video[0].currentTime;
videoSrc = $('source', $video).attr('src', videoFile);
$video[0].load();
$video[0].currentTime = (curtime);
$video[0].play();
}
我的問題是,每次視頻開始播放后/有人找到視頻后,如何觸發此功能? 如果我開ok(); 函數使用播放事件,然后由於該函數本身導致播放事件而開始循環。
有誰對如何解決這個問題有任何想法?
解決方案是在視頻實際開始playing
注冊play
事件。 這樣,它將在暫停或搜索后做出反應。
如果您需要在其他條件下禁用該事件,則只需禁用play
事件(如在playing
功能開始時所做的那樣)...
function test(){
var videoFile = 'trailer.mp4';
var $video = $('#video');
var curtime = $video[0].currentTime;
videoSrc = $('source', $video).attr('src', videoFile);
$video[0].load();
$video[0].currentTime = (curtime);
$video[0].play();
$video.on('playing', function () {
$video.off('play') // remove existing Play event if there is one
console.log("Play event bound")
$video.on('play', function () {
console.log("Video play. Current time of videoplay: " + $video[0].currentTime );
});
});
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.