safarimp3web-audio-apiaudiocontextwebkitaudiocontext

Safari - WebkitAudioContext chokes on some mp3 files for unknown reason


I'm having an issue with certain MP3 files in Safari only.

Here's a codepen: https://codepen.io/parliament718/pen/ExjwWEp

In chrome, both buttons work to play both files. In safari only the first button works.

Why is this? Does safari just choke when it doesn't see a ".mp3" suffix or is it something else?

But only one of the files plays programatically using WebkitAudioContext.

Failing code:

window.webkitAudioContext.decodeAudioData(request.response, ...)

Solution

  • Your MP3 file isn't valid. There is multi-part form garbage at the beginning of the file. If you open it with a hex editor, you'll see it:

    Hex Editor View

    Anywhere else that's playing this file is simply being nice to you. :-)

    Also, use audio/mpeg for your Content-Type header. It doesn't matter in your case since you're using the audio context to decode the data... it doesn't know what the original Content-Type header was. I'm mention it here for others, as it's a common mistake.