androidplayn

Playing music in PlayN: how to pause, resume?


I am playing some background music in my PlaynN game. Everything is fine except it does not pause when the activity is sent to the background. Music still plays when the game is not playing.

I can use Sound.stop() and Sound.play() whenever the window focus changes but then the music restarts from the beginning. I can instead use setVolume(0) and setVolume(1), but it still doesn't sound the way it is supposed to.

I cannot find a working example. I am currently considering the use of a platform specific music player.

Many thanks


Solution

  • To my knowledge, PlayN doesn't support pausing/resuming a Sound, probably because not all platforms support this. However, you might want to take a look at the Android-specific implementation of AndroidAudio, which seems to use a SoundPool backend. The GameActivity seems to already pause and resume sounds when the window gains/looses focus, so I'm not sure why it's not working for you - I believe it has for me. You might try calling these methods manually to test that they work, and if not consider filing an issue.