6

I'm using AudioContext to load an .mp3 file for a game. It used to work fine, but after Safari 15 came out I'm getting reports from people where the sound will not play. The sound used to work fine for them before they upgraded their browser.

On my own Safari 15 it works fine, but for some people the call audioContext.decodeAudioData is failing, they just get EncodingError: Decoding failed and no extra information. I tried using .aac files instead of .mp3 but the same thing happens.

Hard to figure this out since I can't reproduce it myself. Any ideas?

Einar Egilsson
  • 3,438
  • 9
  • 36
  • 47
  • 1
    Having the exact same issue myself. Could not reproduce locally, could not figure out any possible reason for it beyond a new browser bug which I could do nothing about. Ended up catching failed decodeAudioData calls and falling back to a Wasm-backed decoding library (from [wasm-audio-decoders](https://github.com/eshaz/wasm-audio-decoders)). Shaking my fists at Apple that I have to do this, but it seems to work like a charm. – Luke Abbott Oct 05 '21 at 16:59
  • 1
    Note, I actually took the opportunity to switch to Opus audio, which Safari doesn't natively support anyway. [My fork of wasm-audio-decoders](https://github.com/strummachine/wasm-audio-decoders) includes my modifications to do the decoding in a Web Worker, which prevents blocking the main thread (just like decodeAudioData runs in a separate thread). – Luke Abbott Oct 05 '21 at 17:01
  • 3
    Also, in case it's a useful data point, my Sentry logs suggested that this issue was hitting about 20% of Safari 15 users. – Luke Abbott Oct 05 '21 at 17:01
  • @LukeAbbott Thanks, that's very helpful! And the 20% sounds about right, I was getting quite a few messages about this, but nowhere near as many as I'd expect if this was affecting everyone. What makes this extra annoying is that none of the 3 devices I have with Safari 15 are affected, so it's hard to test any workarounds. But I'll look into the wasm-audio-decoder! – Einar Egilsson Oct 07 '21 at 12:40
  • 1
    Cool! And, same: tested on two M1 Macs and two x86 Macs, and of course it worked flawlessly on them. – Luke Abbott Oct 08 '21 at 14:54
  • Ok, I've almost got this working, but I'm decoding a lot of ~1 second sounds and they don't sound quite right, but I still hear something. My code is something like : `let {channelData, samplesDecoded, sampleRate} = this.decoder.decode(new Uint8Array(arrayBuffer)); let buffer = this.audioContext.createBuffer(2, samplesDecoded, sampleRate); buffer.copyToChannel(channelData[0], 0); buffer.copyToChannel(channelData[1], 1);` Sometimes creating a buffer fails, it kinda seems like the decoder keeps some internal state between files. How are you using it? – Einar Egilsson Oct 13 '21 at 16:00
  • 1
    I've tested on 4 machines with Safari 15. Two machines have the decoding issue, two don't. The two that do are running macOS 10.15.7 (Catalina). The two that don't are running macOS 11+ (BigSur). Of course with N=4 this is very inconclusive, but it might be a hint. Anyone else seeing a correlation between macOS version and the issue on their machines? – Reinier Oct 14 '21 at 14:13
  • @EinarEgilsson since you mentioned that you are decoding a lot of files, do you think the problem could be related to this bug: https://bugs.webkit.org/show_bug.cgi?id=227636? – chrisguttandin Oct 14 '21 at 16:34
  • @Reinier I have at least one affected user on Big Sur, so I don't think that's it. – Luke Abbott Oct 14 '21 at 17:16
  • @EinarEgilsson I'm also decoding lots of 1-3 second files. In my web worker, I'm having to "free" the decoder after every file, maybe that's it; see [here](https://github.com/strummachine/wasm-audio-decoders/blob/58c9861da7f997760734c65029c515b685cdffaa/src/ogg-opus-decoder/src/emscripten-post.js#L236). Otherwise I'm using copyToChannel just like you, though I'm falling back to `getChannelData` for Safari < 14.1. – Luke Abbott Oct 14 '21 at 17:21
  • @chrisguttandin I don't think that bug is related because a) it fails to decode even one file, and b) it doesn't crash, it simply fails. – Luke Abbott Oct 14 '21 at 17:24
  • Based on Sentry logs, we are seeing this issue with approximately 5% of our Safari 15 users. All are on 10.15.7. – iccir Oct 16 '21 at 23:18
  • Filed here: https://bugs.webkit.org/show_bug.cgi?id=231872 – iccir Oct 16 '21 at 23:26

1 Answers1

3

There is a sandbox regression affecting Safari 15 with macOS Catalina 10.15. It blocks decoding of audio with web audio

jyavenard
  • 2,142
  • 1
  • 26
  • 35
  • Ok, probably easiest to just wait this one out, any ideas when they plan to release an update that fixes this? – Einar Egilsson Oct 19 '21 at 08:33
  • Have they fixed this yet? How they didn't fast-track a hotfix is beyond me. – ffxsam Dec 29 '21 at 05:53
  • I don’t have the issue on Safari 15.2 (16612.3.6.1.8, 16612) under BigSur, but I have it on STP 137 (Safari 15.4, WebKit 16613.1.11.8), also BigSur. – meduz' Jan 08 '22 at 15:51