简体   繁体   English

在IPAD和IPHONE上进行自动播放

[英]make autoplay work on IPAD and IPHONE

I have fullscreen video background, here is my code: 我有全屏视频背景,这是我的代码:

<div id="video-container">
        <video id="video" autoplay loop>
            <source src="ocean.mp4" type="video/mp4">
            <source src="ocean.ogv" type="video/ogg">
            <source src="ocean.webm" type="video/webm">
        </video>
</div>

how you see it has autoplay attrubute, but on IPAD, IPHONE,etc.. it doesn't work untill you click on play button, but when I add poster attribute for poster image it works: 您如何看待它具有自动播放属性,但是在IPAD,IPHONE等上不起作用。直到您单击播放按钮,它才起作用,但是当我为海报图像添加海报属性时,它起作用:

<video id="video" poster="poster.jpg" autoplay loop>

But I don't want with poster. 但是我不想要海报。 Also I tried to use this js code but no result: 我也尝试使用此js代码,但没有结果:

function startVideo(){ 
        var myVideo = document.getElementById('video'); 
        if ((myVideo.playing) || (myVideo.currentTime > 0)) { 
                // video is already playing 
        } else { 
                myVideo.play(); 
        } 
}   
window.document.body.onload = startVideo;

I guess auto-play feature is not supported in iOS. 我猜iOS不支持自动播放功能。 Check this Apple documentation: 查看此Apple文档:

User Control of Downloads Over Cellular Networks 蜂窝网络下载的用户控制

In Safari on iOS (for all devices, including iPad), where the user may be on a cellular network and be charged per data unit, preload and autoplay are disabled. 在iOS上的Safari(适用于包括iPad在内的所有设备)上的Safari中,用户可能位于蜂窝网络上,并按数据单元收费,因此禁用了预加载和自动播放功能。

Here is the documentation link 这是文档链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM