簡體   English   中英

一個開始時如何停止HTML5中的所有其他視頻

[英]How to stop all the other video in HTML5 when one start

對不起,我的英語不好。

我的網頁中有很多視頻項目,當我開始其中的一個項目時,我希望所有其他視頻都停止播放,希望我可以從一個視頻轉換為另一個視頻

這是我的情況:

網頁:

<video id="..." width="352px" height="288px" poster="..." preload="none" controls="">
    <source src="..." type="video/webm"></source>
</video>

使用Javascript:

$('video').off('canplay').on('canplay', function() {
   this.play();
});

$('video').off('canplaythrough').on('canplaythrough', function() {
   this.play();
});

$('video').off('waiting').on('waiting', function() {
   this.play();
});

我不希望該視頻暫停播放,我希望所有其他視頻處於與加載頁面時相同的狀態(上面帶有播放按鈕的灰色圖像)

$('video').off('play').on('play', function() {
    var dd = this.id
    $('video').each(function( index ) {
        if(dd != this.id){
            // Maybe here the solution...
        }
    });
});

謝謝

如果您想知道如何停止HTML5視頻,則只需將它們pause()並將其currentTime屬性設置為0;

$('video').off('play').on('play', function() {
    var dd = this.id
    $('video').each(function( index ) {
        if(dd != this.id){
            this.pause();
            this.currentTime = 0;
        }
    });
});

或者,您可以調用this.load()來代替視頻的pause()和currentTime的重置,這將重置視頻並再次顯示海報。

<script>

$(document).ready(function(e) {
    $('audio,video').bind('play', function() {
    activated = this;
    $('audio,video').each(function() {
        if(this != activated) this.pause();
    });
});


//flash - prevent simultaneous video playback - pauses other playing videos upon play
$(".video-js").click(function(){
    activated = this;
    $('.video-js').each(function() {
        if(this != activated) _V_($(this).attr("id")).pause();
    });
});
});

</script>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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