播放另一个视频时停止视频 [英] Stop the Video When Play Another Video

查看:38
本文介绍了播放另一个视频时停止视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的页面中,我有很多视频,我想在用 HTML5 播放另一个视频时停止视频.

<?php$result = "SELECT data from events_gallery where `events_id`='$id'";$query = mysqli_query($db, $result);$rows = mysqli_num_rows($query);如果($行> 0){而 ($res = mysqli_fetch_array($query)) {$image = $res['data'];}?><div class="item active"><video controls="controls" playinline width="180" height="300"><source src="images/video.mp4" type="video/mp4"><p>视频不支持</p></视频>

<?php}?>

解决方案

方法在这里

<video class="inlineVideo" controls="controls" playinline width="180" height="300"><source src="images/video.mp4" type="video/mp4" ><p>视频不支持</p></视频>

<script type="text/javascript">window.addEventListener('load', function(event){document.querySelectorAll(".inlineVideo").forEach((el) => {el.onplay = 函数(e){//暂停除当前视频之外的所有视频.document.querySelectorAll(".inlineVideo").forEach((el1) => {如果(el === el1)el1.play();别的el1.pause();});}});});

In my page, I have many videos and I want to stop the video when playing another video in HTML5.

<?php

$result = "SELECT data from events_gallery where `events_id`='$id'";
$query = mysqli_query($db, $result);
$rows = mysqli_num_rows($query);

if($rows > 0){
while ($res = mysqli_fetch_array($query)) {
    $image = $res['data'];
}
?>
<div class="item active">
    <video controls="controls" playsinline width="180" height="300">
        <source src="images/video.mp4" type="video/mp4">
        <p>Video is not Supporting</p>
    </video>
</div>
<?php
}
?>

解决方案

here is the way

<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>

这篇关于播放另一个视频时停止视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆