Остановить видео при воспроизведении другого видео - PullRequest
0 голосов
/ 26 января 2019

На моей странице много видео, и я хочу остановить видео при воспроизведении другого видео в 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
}
?>

Ответы [ 2 ]

0 голосов
/ 26 января 2019

Вы должны полагаться на HTML5 video API для управления своими видео. Вот хорошая отправная точка: https://www.html5rocks.com/en/tutorials/video/basics

Я не вижу в вашем коде, как вы загружаете все свои видео, но первой попыткой может быть остановка всех видео перед воспроизведением:

$(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);
     );
  }
});
0 голосов
/ 26 января 2019

вот путь

<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>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...