Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Shadowbonnie7 opened this issue Jan 15, 2019 · 24 comments · Fixed by #2006
Closed

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

Shadowbonnie7 opened this issue Jan 15, 2019 · 24 comments · Fixed by #2006
Labels
🙇‍♀️Careful thinking/design or refactoring needed Needs a bit of studying to come with an elegant solution 👌good first issue Good issue if you want to start contributing to GDevelop

Comments

@Shadowbonnie7
Copy link

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
Copy link
Contributor

KinkGD commented Jan 15, 2019

+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
Copy link
Contributor

zatsme commented Jan 15, 2019

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

@4ian
Copy link
Owner

4ian commented Jan 15, 2019

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
Copy link
Contributor

zatsme commented Jan 15, 2019

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
Copy link
Owner

4ian commented Jan 15, 2019

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

@Shadowbonnie7
Copy link
Author

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

@zatsme
Copy link
Contributor

zatsme commented Jan 22, 2019

Is this the same issue as #556?

@zatsme
Copy link
Contributor

zatsme commented Feb 15, 2019

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
Copy link
Owner

4ian commented Feb 16, 2019

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
Copy link
Owner

4ian commented Feb 16, 2019

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

@4ian 4ian added 🙇‍♀️Careful thinking/design or refactoring needed Needs a bit of studying to come with an elegant solution 👌good first issue Good issue if you want to start contributing to GDevelop labels Feb 16, 2019
@zatsme
Copy link
Contributor

zatsme commented Feb 16, 2019

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
Copy link
Owner

4ian commented Feb 16, 2019

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
Copy link
Collaborator

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
Copy link
Contributor

zatsme commented May 27, 2019

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
Copy link
Collaborator

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
Copy link
Contributor

zatsme commented May 27, 2019

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
Copy link
Owner

4ian commented May 27, 2019

@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
Copy link
Collaborator

@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
Copy link
Owner

4ian commented May 27, 2019

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

@Silver-Streak
Copy link
Collaborator

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

@4ian
Copy link
Owner

4ian commented May 28, 2019

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

@PascalLadalle
Copy link

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... 🤔
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...

@Bouh Bouh linked a pull request Feb 21, 2021 that will close this issue
@Orghal
Copy link

Orghal commented Mar 18, 2022

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:

  • convert/create your music file as a MP4 -> H.264 and AAC audio (128 or 160 kbps),
  • create object in your project and set it up as Global - right mouse button -> submenu -> choose "Set as global object" (if you want this music across every scene and available to control). Object should change style in list to bold-italic,
  • better when you do it like a small object (it can be few pixels or something) so you can touch it in the scene,
  • for me very simple - I create top right corner small logo, like ID for tv news, tv station etc. It is good for your advertise object :)
  • put it in your starting scene where music start, not need to be in first one,
  • add the Action "Plate the video of [video_name]" in the Events "At the beginning of the scene",
  • it start you music non stop, don't forget loop it,
  • good for this corner "logo" object make a transparency, so if you don't have any graphic content just set it to 0 - so no one see it.

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
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🙇‍♀️Careful thinking/design or refactoring needed Needs a bit of studying to come with an elegant solution 👌good first issue Good issue if you want to start contributing to GDevelop
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants