4ian / GDevelop

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

"Play Music on a Channel" action not working like it used to. #878

Closed Shadowbonnie7 closed 3 years ago

Shadowbonnie7 commented 5 years ago

The action "Play Music on a Channel" does not play your music file. if one was to have music play at the beginning of a scene, no music will play in the preview.

To Reproduce

Steps to reproduce the behavior:

  1. Create a new project.
  2. Put the condition "At the Beginning of the Scene" in conditions.
  3. Put the action "Play a Music File on a Channel" in the corresponding actions and have it play a music file.
  4. Save and preview. Chances are that the music file you told the game to play will not play.

Using Windows

In the meantime, there is a workaround to this problem. If you play the music file as a SOUND instead, it WILL play, like in mobile.

KinkGD commented 5 years ago

+1, i know this bug ! But it's strange because its working on local export. Also, in the preview : if you change scene for another, then come back to the scene where you sound file should play at beginning, it works.. Did you tried to build/export the game to windows (as executable ?).

zatsme commented 5 years ago

Yes, I press Esc to restart scene and as soon as you do that it's working, no delay, odd?!

4ian commented 5 years ago

This is because of a Chrome limitation (which is running GD and previews) that prevent any sound from running if you've not interacted first with the window containing the game. (it's a "feature" of Chrome)

So a sound starting at the beginning of the game won't work. But a sound starting later, or even when you go back to the scene, will work. Have to think about a workaround.

zatsme commented 5 years ago

I understand that, but does it explain why sound command works, but music doesn't?

I just tested and the same mp3 music file doesn't play until scene refresh, but it works fine if played using the play sound command?

4ian commented 5 years ago

Oh not sure about this, will have to investigate what is the difference then!

Shadowbonnie7 commented 5 years ago

I did not export the project, to answer KinkGD's question. Does it work on export?

zatsme commented 5 years ago

Is this the same issue as https://github.com/4ian/GDevelop/issues/556?

zatsme commented 5 years ago

Oh not sure about this, will have to investigate what is the difference then!

Answer is that Music forces HTML5 audio and Sound uses Web Audio by default.

2019-02-15

I changed this line (237) in howler-sound-manager.js and then Sound and Music behaved the same, a delay before playing sound as Web Audio has to load the whole sound, whereas HTML5 Sound plays while loading.

Not sure how you might change it to make it work any better, HTML5 playback is fine after a click or touch!

4ian commented 5 years ago

Super interesting, I never realized this was related to this. Ideally, the long term solution would still to either issue a warning ("for music to work in browsers, you have to launch it after the user interact with the screen") or work around this (put the music to play in some cache, and when the user interact, launch the music that was waiting, so that it's "almost" working).

4ian commented 5 years ago

Actually, updating Howler.js sound library might be enough. I see commits related to audio locking: https://github.com/goldfire/howler.js/commits/master

Could maybe be as simple as replacing howler.min.js file by the new one.

We're on v2.0.7, while 2.1.1 is available. There is a card for it: https://trello.com/c/lV2jnvBq/163-update-howlerjs-to-latest-version

zatsme commented 5 years ago

I'll have a go at updating howler.js as I'm familiar with the issues, is this purely js or was it converted from GD4? Do I just need to check for any API changes, update the js file and test?

4ian commented 5 years ago

This is purely JS.

Do I just need to check for any API changes, update the js file and test?

Exactly :)

If there are some API changes, any changes should be in howler-sound-manager.js (so should be pretty limited - the rest of the engine is agnostic toward the sound manager implementation).

Updating Howler could also bring better compatibility with Safari 12, so would be great to do! :)

Silver-Streak commented 5 years ago

Looks like this was last updated in Feb. I'm seeing a bunch of new folks on the discord asking about this. My understanding is howler is now updated, but this issue still persists (play music/play music on channel do not play any files, while play sound/play sound on channel can play the same files fine).

Is there any other testing I can assist with on this that might help pinpoint it, or is there still a path forwards towards resolution being worked on?

zatsme commented 5 years ago

This is the browser working as designed.

If you play as Music gd forces HTML5 audio, whereas play as Sound uses Web Audio.

See my post 3 months ago for more detail on the differences 😊

Maybe we need to change the ide and doc to say Web Audio instead of Sound, and HTML stream instead of Music. 🤔

Silver-Streak commented 5 years ago

This is the browser working as designed.

If you play as Music gd forces HTML5 audio, whereas play as Sound uses Web Audio.

See my post 3 months ago for more detail on the differences 😊

Maybe we need to change the ide and doc to say Web Audio instead of Sound, and HTML stream instead of Music. 🤔

Thanks for the heads up, Zatsme. Just to check, would that impact Game Preview in addition to exported to HTML? Because using Play Music also doesn't work when previewing a game in most cases.

zatsme commented 5 years ago

ok, hopefully to clear it up:-

If you use play sound:

This uses the older Web Audio which cannot stream files.

Soundfile will load and play as soon as it's completely loaded, almost instantly for short effects, longer for music depending on filesize!!

If you use play music:

This uses HTML5 Audio which can stream files.

Soundfile can start to play as it's being loaded (stream) which is a better/newer system.

However, latest browser fixes do not permit any audio until user interaction so you must make user click/touch first although this could change again and be different for each browser.

Best bet is to have a loding/intro screen to click on and then use the HTML5 Audio to stream the music.

😖

4ian commented 5 years ago

@zatsme is right. No way to work around this (other than loading/intro screen with a click/touch to start). Any idea to make this clearer in GDevelop is welcome!

Silver-Streak commented 5 years ago

@4ian @zatsme Thanks for the info. Recommendations: I would update the description of the Play Music events to specifically call out "This will only work in a browser if the player clicks on the game window itself."

That said, I still want to reconfirm: Does the above explain why the game preview doesn't work with Play Music either? Is preview mode still held by the same limitations as playing a hosted exported HTML game in a browser?

4ian commented 5 years ago

Yes, because preview is running inside (basically) Chrome which has this limitation built in :(

Silver-Streak commented 5 years ago

Thanks for the heads up and clarification. Makes unfortunate sense to me.

4ian commented 5 years ago

I've added this alert when using an action to play a music (or play a music on a channel): image

PascalLadalle commented 4 years ago

Since this is still open, I'm adding feedback from a confused user:

Lotness: yeah I read that [warning]... from what I understood music should have started once I moved my character around (user interaction) and it wasn't working. that's why I was a little confused :slight_smile: Me: hmm...we can try to rephrase it, but the last sentence should be clear enough... :thinking: Lotness: yup, it seemed plenty clear. From how I read it, the action I had set out should have started playing once I started moving my character around, or firing or a jump or any other mouse/keyboard event.

So the warning has been understood as "music will only be played when user has interacted with the game". Perhaps something more practical: "This action is incompatible with "at the beginning of the scene". In such cases, use the sound actions instead.", because I guess that most music files are meant to be played at the beginning of scenes...

Orghal commented 2 years ago

Hello guys, I am beginner here so I try make clear description - here is real solution for you all. I found this out after many trials and compilations because like all of you know - peoples, users and probably customers too, hate technical problems, do not understand Chrome or any browser configurations and especially what is this called "streaming". For us all of it is clear but here it is, how to skip the problem once and happy:

I checked it after 3 hours testing, compilations and publishing and it works:

All of this I checked in build application - any kind, publish for website (Liluo.io) and... it works :) Not sure every Android but I checked 8.0, 8.1, 9.0 and 11 it is okay too.

Very nice option to do any video especially for this problem if free software DaVinci Resolve 17, my recommendation guys :) Video settings for the smallest thing (you can scale it on the scene later), and very small file with music: Format: MP4 / Codec H.264 / Resolution 420 x 256 / Frame rate - any, if you make nice logo 24 is enough :)

My logo with music its just 2MB and fade-in/out only.

Best regards to all Orghal

Silver-Streak commented 2 years ago

Hello @Orghal,

Normally you shouldn't be posting in a closed issue, especially one that has been closed for ~3 years.

For the issue in this thread, the recommended solution is to use the "Play a sound on a channel" events instead of the "Play a music on a channel". Keep in mind "Play a sound" means "Play a sound file" not "Play a sound effect"

I'm glad you found another solution that works for you, but keep in mind it isn't needed to avoid this issue with audio files not starting with the game before it is interacted with.