Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Current solutions to preload, cache, or otherwise play audio without lag / delay on mobile Safari in HTML5? Perhaps iOS 5+

There are a ton of SO posts on audio, HTML5, and mobile Safari, such as these:

Reusing HTML5 Audio Object in Mobile Safari Autoplay an Audio File on Mobile Safari Preloading HTML5 Audio in Mobile Safari Will HTML5 support the access of offline cached audio?

However, they all are outdated.

We prefer solutions to support iOS 3+, but we will take anything that works -- even if it's restricted to iOS 5.

Anyone have the definitive answer as things stand today, or testers on iOS 5 have any insights?

  • Can audio files be cached in mobile Safari? If so, what are the limitations?
  • Is there a way to minimize lag or delay between pressing a button and playing a sound?

Thanks!

like image 758
Crashalot Avatar asked Oct 18 '11 20:10

Crashalot


1 Answers

I recently wrote an HTML5 audio player. I had similar trouble with iOS4 and iOS5. First, the play has to be triggered by user input, meaning specifically that it has to be in the same call stack as a click event.

I tested this a lot, and iOS seemed to refuse to cache the audio at all. It fetched the audio with every play. I think this should be considered a bug, but perhaps they are trying to preserve local storage space (audio files can get rather large).

If your audio files are not too large, you might want to consider appending them together into a single file and then using pause / jump to position / play to switch between sounds. I haven't tried it, but it should work. I didn't use the technique because my app was a music player, and music files are a bit too large for that technique to be valuable.

like image 88
Eric Elliott Avatar answered Oct 16 '22 19:10

Eric Elliott