4ian / GDevelop

🎮 Open-source, cross-platform 2D/3D/multiplayer game engine designed for everyone.
https://gdevelop.io
Other
9.04k stars 786 forks source link

Music volume on channel has no effect in iOS #2075

Open krunkster opened 3 years ago

krunkster commented 3 years ago

Description

Using the "Play Music on Channel" with a specific volume, or calling "Change music volume on channel" has no effect when running on iOS browsers. This bug occurs on both Safari and Chrome iOS versions, as well as native mode when built using Cordova. It is easiest to reproduce using a network preview and loading on safari iOS.

To Reproduce

I've attached a reproduction. ios-music-volume-bug.zip

  1. It plays the music twice and requires a touch to workaround iOS restriction on music launching
  2. Touching anywhere will play "fantastic" sound at current volume
  3. Touching +/- text will change the volume and trigger volume change used by sound effects and music
  4. Notice as the volume changes the sound effect is played at different volumes, and the music stays at the same volume (when viewing in iOS browser... in other places the music volume changes dynamically)

Other details

krunkster commented 3 years ago

I forgot to highlight the fact that the volume on the sound effect channel does change as expected. So I can work around this issue by changing all of the "Music" calls to "Sound" calls. The two sets of methods seem to have parity in functionality... but it's still a bug. It feels like I should be using music calls for playing music, and sound calls to play sound effects... but I'm not really sure what the difference is... so not sure if I should just work around this issue or wait for bug fix.

krunkster commented 3 years ago

I looked through the code, and it seems to me that Gdevelop is using the Howler library, and your use of that library is making a distinction between Sound and Music, but the only difference at the library level is whether "html5 audio" is enabled (which it is for Music and not for Sound methods).

So I researched that a bit and it appears that volume for "HTML5 Audio" on iOS is dictated strictly to user control. Using WebAudio the volume can be manipulated using software.

WebAudio loads the entire file into memory, and HTML5 Audio streams the file from the server.

There is a newer WebAudio API called AudioBufferSourceNode that may allow streaming like HTML5 audio, but it's not clear whether Howler is adopting that already or how to leverage it.

Work Around If your use of music (like mine) is from fairly small mp3s, just switch to using GDevelop's Sound methods (instead of Music) to ensure iOS compatibility.

Some helpful articles I found: https://stackoverflow.com/questions/27296391/is-there-any-possibility-to-control-html5-audio-volume-on-ios https://github.com/goldfire/howler.js/issues/415#issuecomment-487263098

4ian commented 3 years ago

Thanks for the in-depth analysis! I believe you're right and this is a limitation that we have to document somewhere. I think something in the wiki would be good: http://wiki.compilgames.net/doku.php/gdevelop5/all-features/audio

If your use of music (like mine) is from fairly small mp3s, just switch to using GDevelop's Sound methods (instead of Music) to ensure iOS compatibility.

Sounds like a good workaround indeed.