Background Music not working on android but works in preview

I added a music file in a channel but the music is not working on android at all like i didn’t even put it .
In preview however it’s working great .
The music file is mp3 (Also tried wav. and same problem)

so how to fix that ?

I have the same issue with Sakawochi on both devices I could test it on.

Browsers on mobile devices are limited and music can not be plaid before the user touch the screen. In most HTML5 game engines you can work around this by simply asking the player to press a button in order to start the game. If player press the button, the screen has been touched and the app start playing the music.

Unfortunately though it doesn’t seems to solve the problem in GD5 not sure why.
One way you can work around this in GD5 is to play the music as a SOUND instead of music but the player still need to touch the screen once in order to get the music playing.

I have uploaded a test, see if it works for you, it does for me.
gametemplates.itch.io/play-musi … sword=test

I’m also going to upload this as an example of playing music on mobile with GD5, though it is not very practical but I did not find any better ways to do it :frowning:

OK i tried it on android mobile … it works when it’s (as a sound) and (when player press something on screen) but 3 problems occur :-

1- there is a huge delay to even start the music (20 seconds)
you press the button > then wait for around 20 seconds > then it works

2- when the music is on … other sound effects don’t work properly at all

3- the last thing which is the most important one … the game just turns into (lag) and the Fps becomes a mess .

So what is going on here ?

A few things possibly. As I mentioned mobile browser, at least Chrome and Opera doesn’t play music until the user touch the screen, it is just the way it is and when you export to Android technically you wrap the game in to Chromium, the same thing as playing the game in Chrome. The other thing is GDevelop does not preload the audio and when you touch the screen and the action being executed to play the music, then it start loading that’s why the 20 seconds delay possibly, an other possibility is slow broadband in case you are running in the browser but then it should play fine the second time.

Regarding the 20 seconds delay, If you want to play the music at the beginning, then play it At the beginning but make the user touch the screen by putting a button on the screen or simply a message to touch it to start. The button or touch doesn’t need to actually do anything with the music just make the user touch the screen. My old device running Android 4 start playing the music almost immediately this way because the music get loaded at the beginning, only waiting for the touch to start playing.

Regarding other problems, it could be actually the result of playing the music as a sound as the sound object is designed to play multiple instances of the same sound it is not meant to be used for playing music really. What you can try though make sure you are playing all sound files on their own channels never play different sound files on the same channel. Also make sure you are playing the music only once by either playing it at the beginning or checking first if the sound is NOT playing on the channel then play the sound on the channel and make sure all other sounds are being plaid only once at the time by using the Trigger Once condition.

I have just tested the performance on multiple Android devices running different versions of Android and I’m getting stable 60 FPS and no delay and lag even if I’m playing multiple sound effects with the music. In case you don’t, could you please let me know the exact model of the device you are testing it on and are you sure the audio playback causing the lag? Thanks.

Cool … I fixed it and the game now runs even better
Been working for about 8 hours now to make it work
So all i did was … i made a ( loading screen )
So i measured the delay the song need to load then i made a loading screen within this time (8 seconds)
And not just that … the great part is that i made the whole pictures and other stuff in the whole game to load before even the game starts … which made the (levels-animations-sound-controls…etc.) run super smooth … no more lag … music is working … effects are working … all good .

Thank you so much for your help …
Oh and I’m testing on ( Lenovo A6010 )

Need to try this too when I get home.

With “music” do you mean playing the music file as a sound or as music?

No just as a sound file
As a music file it takes longer to load in
Also you need to make the sound file around 20 seconds long and just keeps looping … that will take around 10 seconds to just load in …
Also when it’s loaded the first time and the game still running … the song will run immediately the second time if it have to .

Also as ddabrahim suggests :-

Play every sound effect in it’s own channel … This will make the effects run correctly because when the music is running (or longer sound) the game lags a bit on other sound effects that is in the same channel .

And for sure (don’t forget you need the player to touch the screen in order for any music to load in the game) .

Good luck . Hope you fix it soon