not-fl3 / macroquad

Cross-platform game engine in Rust.
Apache License 2.0
3.23k stars 313 forks source link

Playing OGG files crashes in WASM on Safari/iOS #533

Open ollej opened 1 year ago

ollej commented 1 year ago

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 commented 1 year ago

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

not-fl3 commented 1 year ago

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

ollej commented 1 year ago

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.

macnelly commented 1 year ago

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.