Android background music

Hi,
I’ve a problem.
If i’m listening music in my Android device and I run my game, the music that I’m listening is stopped. I would like to listen the music in background. Anyone know how can I do it?

In iOS works fine.
Thanks

1 Like


I hope that it will be fixed in next version…

1 Like

Perfect. It works! Thanks!!

But isn’t this just a complete turn off of the AudioFocusListener? To disable this in the onResume isn’t good. It should be coupled to a “music on/off” switch, because some games want to use music and the user can disable it, so he/she can hear own music.

This “fix” is just a all or nothing fix, as far as I understand it.

Hi @mars3142
In my case, it works ok. My game has music and sounds, and if I’m listeting music I run the game and I listen both musics (my music and game music and game sound). If I turn off game musics I listen only my music.

Recently I uploaded a new version in Play Store. If you want, you can test it with your device. Download the game powBox :slight_smile:

Okay, but … Hmmm

Okay, I checked what the call is doing in the Android docs. It seems to be fine to remove it, without any problems. It’s just a “mute other music playing apps” command and seems to have no impact of playing music within the audio system.

Also in the Cocos2dxAudioFocusManager.registerAudioFocusListener there is a AudioManager.AUDIOFOCUS_GAIN. If you change this to AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK it should (as described in the docs) lower the other music volume instead of turning it off.

@CrazyHappyGame Thanks for showing the API call for that.

PS: But I wouldn’t recommend it and would really bind it to a “no music” option within your game. So if the user did want to hear the game music, it should stop other music players.

@mars3142 it seems like there is pull request with fix. Could you review it and add comment that by default user should be able listen music?

The comment of the contributor was a good one. I also added one comment.