HaxeFlixel / flixel

Free, cross-platform 2D game engine powered by Haxe and OpenFL
https://haxeflixel.com/
MIT License
1.97k stars 434 forks source link

HTML - audio in Mode HTML5 demo doesn't work on safari on osx #2197

Closed increpare closed 4 years ago

increpare commented 5 years ago

Code snippet reproducing the issue:

whatever version is used on the website build

Observed behavior: In safari 12.0.1, I hear nothing. In chrome 70.0.3538.110 I hear sound fine. I'm on macOS 10.14.1

Expected behavior: I would like to hear sounds on both.

(this is probably due to how safari handles audiocontexts now ( https://hackernoon.com/unlocking-web-audio-the-smarter-way-8858218c0e09 ), and how chrome will very, very soon ( https://groups.google.com/a/chromium.org/forum/#!msg/blink-dev/5Y1BqbGauEs/rRocaytKBgAJ ) )

MSGhero commented 5 years ago

I think it’s due to Safari not being able to play OGG files.

Gama11 commented 5 years ago

I think Mode includes both mp3 and ogg assets on HTML5.

TheSpydog commented 5 years ago

This is the same issue I encountered back in May, but for me, the game just freezes entirely -- it doesn't even play silently. Just checked on Safari 12.0.2 and it still has that behavior. Strange...

EDIT: Project Jumper used to play audio, but it doesn't anymore. I'll investigate further. Maybe something did change in Safari.

transmutrix commented 5 years ago

Hi. I was trawling the issues page for something unrelated, but: I had a similar experience with one of my html5 games not using flixel. New versions of Safari will block audio playback until an html game’s canvas has been interacted with (a click or touch).

One solution is to add a window listener on the JavaScript side to start / resume audio playback on the first interaction and then remove itself from event listeners.

Hope this helps.