views:

52

answers:

2

When I press back or home in my application, it hides, but the MediaPlayer keeps going. Is there a way to know when these buttons have been pressed and stop playback before closing?

+1  A: 

You should be able to override the onPause() function in your Activity. onPause() will be called when you Activity is hidden and you can pause the MediaPlayer there.

For example,

@Override
protected void onPause() {
    super.onPause(); // Don't forget this line
    myMediaPlayer.pause() // Or whatever the function is to pause it
}
Computerish
This causes a crash.
Joel Auterson
@Joel Can you provide more details, such as a stack trace?
MatrixFrog
I'm now not totally sure that this was what was causing the crash. Let me get back to you...
Joel Auterson
devvy is correct. I updated my post with more information.
Computerish
+1  A: 

Don't forget to add super.onPause; if you forget it will cause a FC.

devvy