16

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!

Community
  • 1
  • 1
Crashalot
  • 33,605
  • 61
  • 269
  • 439
  • 1
    Great question. I have spent many hours trying everything I think of and have been unable to remove the delay on first play. – Chris Broski Nov 02 '11 at 14:26

1 Answers1

7

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.

Eric Elliott
  • 4,711
  • 1
  • 25
  • 33
  • i posted a question before finding this one as well: https://stackoverflow.com/questions/51029867/why-does-the-browser-load-audio-files-several-times-even-after-preload. As described there: I also found that safari mobile sometimes does cache when i preload soundfiles and sometimes not. most of the times it does the caching partially. which is particularly annoying because it produces inconsistent behaviour. – gaugau Jun 26 '18 at 13:30