Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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 player.play() is called in any asynchronous fashion (ajax, setTimeout, etc) it doesn't work.

I've tried calling player.load() before player.play(). I've tried triggering a click event on a dom element whose handler calls player.play(). I've tried using both audio and video tags.

All the loopholes that worked prior to iOS 4.2.1 seem to be closed. Any ideas?

like image 347
David Gouldin Avatar asked Nov 23 '10 19:11

David Gouldin


People also ask

How do I turn on Autoplay in Safari iOS?

Click on Safari > Preferences on the top menu. Click on the Websites tab at the top. Click on Auto-Play in the left column.

How do I make videos play automatically in Safari?

Hold the pointer to the right of Auto-Play, then click the pop-up menu and choose an option: Allow All Auto-Play: Lets videos on this website play automatically. Stop Media with Sound: Blocks autoplay for videos that contain audio, but allows other videos to play.

Does Autoplay work in Safari?

As of version 11 released in September 2017, Safari autoplay policy states that: Muted autoplay is allowed as long as users haven't blocked all autoplay in their settings. Autoplay with sound is only allowed if users configure it in their settings.


2 Answers

Starting from iOS 4.2.x, the download of media will not be started if there isn’t a user-input event, like touchstart.

So the answer is no, there is no method to autoplay media by JavaScript or something else.

like image 102
Yu Jianrong Avatar answered Nov 21 '22 18:11

Yu Jianrong


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);
like image 21
bhups Avatar answered Nov 21 '22 18:11

bhups