簡體   English   中英

搜索/播放HTML5視頻時觸發功能

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM