【问题标题】:Safari video not working but all browser work autoplay. multiple video play one by oneSafari 视频不工作,但所有浏览器都可以自动播放。多个视频一一播放
【发布时间】:2019-03-19 07:31:34
【问题描述】:

**html5 视频 Safari 自动播放不工作 ????????? 我的多个视频播放代码工作得很好,但它不工作 Safari 浏览器有任何方法可以在 Safari 中启动自动播放也请帮我这个查询。在 safari 浏览器中使用和工作正常的任何方式。 有任何其他方法可以使用它。 谢谢 该代码只是我用来创建 ID 并用于在浏览器中播放视频的 HTML 和 js CSS。 **

    <div class="video-container " id="video_auto_play">
<video autoplay="autoplay" controls muted id="home_videoPlayer" style="object-fit: initial;" >
  <source id="home_videoPlayer" style="object-fit: initial;"  type="video/mp4" />
</video>
<script> 
    document.getElementById('home_videoPlayer').play(); 
</script>
</div>


<script>
var videoSource = new Array();


videoSource[0] = 'a1.mp4';
videoSource[1] = 'a2.mp4';
videoSource[2] = 'a3.mp4';
videoSource[3] = 'a4.mp4';

var i = 0; // define i
var videoCount = videoSource.length;

function videoPlay(videoNum) {
    document.getElementById("home_videoPlayer").setAttribute("src", videoSource[videoNum]);
    document.getElementById("home_videoPlayer").play();
    document.getElementById("home_videoPlayer").play();
}
document.getElementById('home_videoPlayer').addEventListener('ended', myHandler, false);
videoPlay(0); // play the video

function myHandler() {
    i++;
    if (i == (videoCount - 0)) {
        i = 0;
        videoPlay(i);
    } else {
        videoPlay(i);
    }
}
</script>

【问题讨论】:

    标签: javascript css html


    【解决方案1】:

    它工作正常。您是否在菜单栏中检查了 Safari > 本网站的设置?

       document.getElementById('home_videoPlayer').play(); 
    
    
    var videoSource = new Array();
    
    
    videoSource[0] = 'https://www.w3schools.com/tags/movie.mp4';
    videoSource[1] = 'https://www.w3schools.com/tags/movie.mp4';
    videoSource[2] = 'https://www.w3schools.com/tags/movie.mp4';
    videoSource[3] = 'https://www.w3schools.com/tags/movie.mp4';
    
    var i = 0; // define i
    var videoCount = videoSource.length;
    
    function videoPlay(videoNum) {
        document.getElementById("home_videoPlayer").setAttribute("src", videoSource[videoNum]);
        document.getElementById("home_videoPlayer").play();
        document.getElementById("home_videoPlayer").play();
    }
    document.getElementById('home_videoPlayer').addEventListener('ended', myHandler, false);
    videoPlay(0); // play the video
    
    function myHandler() {
        i++;
        if (i == (videoCount - 0)) {
            i = 0;
            videoPlay(i);
        } else {
            videoPlay(i);
        }
    }
    <div class="video-container " id="video_auto_play">
    <video autoplay="autoplay" controls muted id="home_videoPlayer" style="object-fit: initial;" >
      <source id="home_videoPlayer" style="object-fit: initial;"  type="video/mp4" />
    </video>
    </div>

    【讨论】:

    • 感谢您的重播,但这不是正确的方法,我不能去我的客户和客户 Iphone 浏览器并每次都更改设置。如果有任何可以更改它的代码方式或代码自动播放中的任何错误适用于所有 Safari 浏览器。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-13
    • 1970-01-01
    • 2017-05-08
    • 1970-01-01
    • 2018-08-29
    相关资源
    最近更新 更多