** html5视频safari自动播放无法正常工作?????????我的多个视频播放的代码一个接一个工作正常,但它不工作safari浏览器有任何方法在safari中启动自动播放也请帮我这个查询。任何方式在safari浏览器中使用和工作正常。还有其他方法可以使用它。感谢代码只有HTML和js CSS我正在使用听到创建一个id并用于在浏览器中播放视频。 **
<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>
它工作正常。您是否在菜单栏中选中了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>