Manish
Manish

Reputation: 1972

Android stopping mediaplayer on activity leave/stop but not on orientation change

I am using MediaPlayer to play some sound in my app, I want this playback to stop when user leaves activity in which sound is being played. So I did this by calling mediaplayer.stop() in my activities onStop() method.

public void onStop() {
 super.onDestroy();
 mediaPlayer.stop();
 mediaPlayer.reset();
}

but now when device rotation changes even then sound playback stops,because onStop() method is called, which I don't want, playback should continue when device orientation changes. How can this be done.

Upvotes: 0

Views: 897

Answers (1)

marshallino16
marshallino16

Reputation: 2671

Just add this ligne to your Manifest.xml inside the <Activity> you are focusing with that trouble :

android:configChanges="keyboardHidden|orientation|screenSize"

Upvotes: 0

Related Questions