macroquad icon indicating copy to clipboard operation
macroquad copied to clipboard

Playing OGG files crashes in WASM on Safari/iOS

Open ollej opened this issue 3 years ago • 5 comments

Playing an OGG file crashes in Safari on Mac. It seems to be the same issue for iOS, as nothing happens, but I haven't checked the console. It works fine in Firefox and Chrome on Mac, as well as natively on Mac.

Browser: Safari Version 16.1 (18614.2.9.1.12) OS: MacOS 13.0.1 (22A400) Ventura CPU: Apple M1 Max

Macroquad: 0.3.25 quad-snd: 0.2.5

Error message from javascript console in Safari:

[Error] Failed to decode audio buffer – null
	(anonymous function) (mq_js_bundle.js:1532)
[Error] Unhandled Promise Rejection: EncodingError: Decoding failed
	(anonymous function)
	rejectPromise

I've made a minimal example, which is basically just loading the test.ogg file from the quad-snd repo and playing it.

#[macroquad::main("Safari sound issue")]
async fn main() {
    let sound = load_sound("assets/test.ogg").await.unwrap();
    play_sound(
        sound,
        PlaySoundParams {
            looped: true,
            volume: 1.,
        },
    );
    loop {
        next_frame().await;
    }
}

Full example with compiled WASM demo: https://github.com/ollej/macroquad-safarisoundissue

ollej avatar Dec 13 '22 21:12 ollej

Looks like Safari doesn't support OGG vorbis: https://caniuse.com/ogg-vorbis

ollej avatar Dec 14 '22 10:12 ollej

yes, macroquad on web is just feeding the whole file to the browser instead of parsing it, therefore if the browser does not support ogg - this is not going to work :(

not sure what the correct fix would be here

not-fl3 avatar Dec 14 '22 16:12 not-fl3

Possibly a more informative error message and/or a note in the docs. I'm fine with just closing the issue as well.

I thought about writing a js function that detects the browser and chooses file type based on that. But for now, converting to WAV seemed good enough.

ollej avatar Dec 14 '22 17:12 ollej

I think ogg support will not come to Safari. The issue is opened since at least 2014. So we should use another format for all browsers or detect safari and have a fallback audio format for safari users.

macnelly avatar Dec 15 '22 07:12 macnelly

Looks like ogg support finally shipped 2 weeks ago in Safari 18.4, but https://caniuse.com/ogg-vorbis says about 14% of users (between desktop and iOS Safari) are still on old versions that don't support ogg.

Maybe in a year or so we can have nice things.

caspark avatar Apr 14 '25 01:04 caspark