Javascript 当一个视频启动时,如何停止HTML5中的所有其他视频
对不起,我的英语不好 我的网页上有很多视频项目,当我启动其中一个时,我希望所有其他视频停止播放,我希望我能从一个视频切换到另一个视频 这就是我的情况: 网页:Javascript 当一个视频启动时,如何停止HTML5中的所有其他视频,javascript,jquery,html,html5-video,Javascript,Jquery,Html,Html5 Video,对不起,我的英语不好 我的网页上有很多视频项目,当我启动其中一个时,我希望所有其他视频停止播放,我希望我能从一个视频切换到另一个视频 这就是我的情况: 网页: <video id="..." width="352px" height="288px" poster="..." preload="none" controls=""> <source src="..." type="video/webm"></source> </video>
<video id="..." width="352px" height="288px" poster="..." preload="none" controls="">
<source src="..." type="video/webm"></source>
</video>
我不希望该视频暂停,我希望所有其他视频与加载页面时处于相同的状态(上面带有播放按钮的灰色图像)
谢谢如果你想知道如何停止HTML5视频,你只需暂停它们并将它们的
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()
来重置视频并再次显示海报,而不是暂停()和重置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>
$(文档).ready(函数(e){
$('audio,video').bind('play',function(){
激活=此;
$('audio,video')。每个(函数(){
如果(this!=激活)this.pause();
});
});
//flash-防止同时播放视频-播放时暂停其他播放视频
$(“.video js”)。单击(函数(){
激活=此;
$('.video js')。每个(函数(){
如果(this!=已激活)_V_($(this).attr(“id”)).pause();
});
});
});
我尝试使用此.load()重置视频并再次显示海报,问题是使用此.load()我有一个奇怪的效果:视频显示海报并立即开始。我认为这是因为:$('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){
this.pause();
this.currentTime = 0;
}
});
});
<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>