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?
Click on Safari > Preferences on the top menu. Click on the Websites tab at the top. Click on Auto-Play in the left column.
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.
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.
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.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With