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