I want to play an audio file in the background of my application. Simple enough. I want the music to be saved and NOT to stop and not pause when switching between actions in my application. It is also quite easy and simple to do this using the onCreate method:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
mp = MediaPlayer.create(MainActivity.this, R.raw.lostmexicancity);
mp.setLooping(true);
mp.start();
}
This problem? Getting music to stop when I press the HOME button.
Killing the sound when the user presses the back button seems easy. Here's what works fine for me:
public void onPause() {
if(this.isFinishing()){
mp.stop();
}
super.onPause(); }
Not difficult, but it doesn’t catch pressing the HOME button. If you click the Home button, the music will continue to play even if the user no longer sees my application.
, , , . , . , , , "" STILL , , , , "" ( , , - , , )
, , "", - stop() onPause, , , , ,
, , , , , , , , .
Google Play , , , ? onPause(), , , , .