How can I autoplay media in iOS >= 4.2.1 Mobile Safari?

后端 未结 9 1087
半阙折子戏
半阙折子戏 2020-11-27 05:28

I cannot seem to get audio media to play in Mobile Safari on iOS 4.2.1 in any situation other than the handler of a click event performed by the user. Even then, if p

9条回答
  •  孤独总比滥情好
    2020-11-27 06:02

    There is one way to play the video/audio file automatically on 4.2.1. Create an iframe and set its source to the media file's URL and append the iframe to the body. It'll be autoplay.

    var ifr=document.createElement("iframe");
    ifr.setAttribute('src', "http://mysite.com/myvideo.mp4");
    ifr.setAttribute('width', '1px');
    ifr.setAttribute('height', '1px');
    ifr.setAttribute('scrolling', 'no');
    ifr.style.border="0px";
    document.body.appendChild(ifr);

提交回复
热议问题