Looping music on android

Hi all,

I have some background music playing on my android app, which works as expected. When another activity overtakes the screen, the music pause as expected and resumes once the jME app is in the foreground again. However, if I use the “back” button, which invokes the “stop” method, the background music continues to loop indefinitely. I trace the cause of this back to AndroidHarness where audio is explicitly paused in the onPause() method but nothing is done in the onStop method.

I tried putting the audio stop code inside the onStop() method but that doesn’t work since we cannot count on onStop() to be called according to the official Android doc. I decided to put an explicit stop to the audio by overriding the stop() method of Application (which is called by the “Do you want to exit” dialog box).

What I’m wondering is if this is the right thing to do? Or is there a different way to handle this situation? Basically, we need to find a way to stop looping music from playing on exit.

Thanks!

sigh… audio on android… what a mess…
There is an issue in the tracker about it. Though the proposed solution of the tracker was to refactor the pauseAudio code to be able to call it from stop of from anywhere.

Stopping audio in jME app stop seems fine to me, as far as your target is android only…I guess it makes no sense for desktop. We should find a solution in the Harness.

Ok, at least I know that the behavior is expected. Could I have the link to the tracker issue? Maybe I can help since I’m working on it anyway.

1 Like

yeah sure
http://code.google.com/p/jmonkeyengine/issues/detail?id=566&q=patch&colspec=ID%20Type%20Status%20Component%20Priority%20Difficulty%20Product%20Milestone%20Owner%20Summary