Javascript 播放其他视频时停止视频
在我的页面中,我有很多视频,我想在播放HTML5中的另一个视频时停止该视频Javascript 播放其他视频时停止视频,javascript,php,html,Javascript,Php,Html,在我的页面中,我有很多视频,我想在播放HTML5中的另一个视频时停止该视频 视频不支持 这是方法 <div class="item active"> <video class="inlineVideo" controls="controls" playsinline width="180" height="300"> <source src="images/video.mp4" type="video/mp4" >
视频不支持
这是方法
<div class="item active">
<video class="inlineVideo" controls="controls" playsinline width="180" height="300">
<source src="images/video.mp4" type="video/mp4" >
<p>Video is not Supporting</p>
</video>
</div>
<script type="text/javascript">
window.addEventListener('load', function(event){
document.querySelectorAll(".inlineVideo").forEach((el) => {
el.onplay = function(e){
// pause all the videos except the current.
document.querySelectorAll(".inlineVideo").forEach((el1) => {
if(el === el1)
el1.play();
else
el1.pause();
});
}
});
});
</script>
视频不支持
window.addEventListener('load',函数(事件){
document.queryselectoral(“.inlineVideo”).forEach((el)=>{
el.onplay=功能(e){
//暂停除当前视频外的所有视频。
document.queryselectoral(“.inlineVideo”).forEach((el1)=>{
如果(el==el1)
el1.play();
其他的
el1.暂停();
});
}
});
});
你应该依靠HTML5视频API来控制你的视频。
这是一个很好的起点:
我无法在您的代码中看到如何加载所有视频,但第一次尝试可能是在播放视频之前停止所有视频:
$(document).ready(function(){
// Add an eventlistener to all videos to detect when they start playing.
$("video").each(function(){
var video = $(this)[0];
video.addEventListener("playing", function() {
// Stop all other videos.
$("video").each(function(){
if($(this)[0] != video)
video.pause();
});
}, true);
);
}
});
确保将脚本标签放在头中,刚好在结束标签(之前)之前,它就会工作。谢谢你。非常感谢你。。这其实是我需要的。