Anyway, in the remainder of this post I am going to share with you two severe limitations of HTML5 audio in Mobile Safari on iOS, Apple's browser for the iPhone and iPad. While I was adding sounds to an iPad compatible hangman game for my daughter (that I have referred to before) I discovered the following restrictions:
- You cannot preload sound files or cache them in the HTML5 application cache.
- You cannot play audio automatically, i.e. without the user clicking on some element. Technically speaking, the audio must be played in the same call stack as a click event.
The first limitation makes the HTML5 audio support in Mobile Safari almost useless for the moment. If you cannot preload sounds, and they are instead fetched from the network with every play, there is a big chance that there will be a delay before playing them. This guarantees a bad user experience.
Also, I have not been able to store sound (MP3) files in the HTML5 application cache. Maybe they are cached by Mobile Safari (the opinions on this vary) but they certainly are not played. Hence there is no way I can combine an offline game experience with playing audio, which is a pity.
As far as I have been able to discover there are no current workarounds for this. If you know of any, please let me know by leaving a comment! By the way, I have been testing in Mobile Safari on iOS 5.0.1 on an iPad 2.
I will conclude with the explanation that Apple gives for disabling preloads on sound files (quote from the Safari Developer Library):
My suggestion to Apple: Why not ask the user for permission to (pre)load audio like has been done with the Geolocation feature?