Hi friends I have an issue with Android media player. It is working but when I change the screen orientation, control with media player is lost, that is initially I am able to pause and stop the song, but once the screen orientation changes the song continues but I am unable to pause or stop etc.
This is the code I tried (I put the song in raw folder)
setContentView(R.layout.activity_medial_player);
mp = new MediaPlayer();
playPause = (Button)findViewById(R.id.buttonPlay);
playPause.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(mp.isPlaying()) {
if(mp!=null) {
System.out.println("*******");
mp.pause();
}
} else {
if(mp!=null) {
System.out.println("#######");
mp.start();
}
}
}
});
startSong= (Button)findViewById(R.id.buttonStart);
pause.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// mp.pause();
playSong();
}
});
stop = (Button)findViewById(R.id.buttonStop);
stop.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mp.stop();
}
});
}
public void playSong() {
try {
mp.reset();
mp = MediaPlayer.create(MedialPlayer.this, resId);
mp.start();
} catch(Exception e) {
}
}
In Manifest I use:
android:configChanges="orientation|keyboard|keyboardHidden"
Any help please…
What is your API level ?
If your application targets API level 13 or higher (as declared by the minSdkVersion and targetSdkVersion attributes), then you should also declare the “screenSize” configuration, because it also changes when a device switches between portrait and landscape orientations.
Source : http://developer.android.com/guide/topics/manifest/activity-element.html