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?
Please Try this Code it is working both version, you need to add the audio control dynamically in page. it is working.
How about this?
Create an audio sprite with Sound Manager 2, preload & cache it from the first user interaction, and then play as and when needed.
Would that work?
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.
As a workaround, I tried tying the load()/play() code to a click event, and then triggering the click event programmatically. This approach worked in Desktop Safari, but not Mobile Safari.
Autoplay is supported (in my tests) with an iPhone 5 (iOS 6) using the headphone jack.
As others have said here and according to Apple documentation, MobileSafari does NOT support the autoplay attribute in the video tag. However, in iOS 6 it DOES work. This appears to be a bug which Apple fixed in iOS 6.0.1 (and presumably in iOS 6.1).
Don't rely on autoplay working in iOS 6 if you happened to stumble across it working in iOS 6.0.
-Michael