Reputation: 215
I need save the MediaPlayer object on android screen rotatio.
But i not know can execute this action.
some people can help me?
Upvotes: 0
Views: 466
Reputation: 215
ok nice!
Thanks for your Answer.
I implementing my class with this code.
public class MyMediaPlayer extends MediaPlayer {
private static MediaPlayer mp;
private static MyMediaPlayer instance = null;
private MyMediaPlayer() {
}
public static MyMediaPlayer getInstance () {
if (instance == null) {
instance = new MyMediaPlayer();
}
if (mp == null) {
mp = new MediaPlayer();
mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
//mp.setOnPreparedListener(this);
//mp.setOnErrorListener(this);
try {
mp.setDataSource("http://74.222.1.197:13588");
} catch (Exception e) {
// TODO: handle exception
}
}
return instance;
}
public MediaPlayer getMediaPlayer() {
return mp;
}
}
Upvotes: 0
Reputation: 426
I will recommend write a singleton class which extends MediaPlayer and then write methods which you want to use for media playing pausing resuming etc. Now you can save call pause() for that singleton class before rotation and when screen is rotated then resume() your player.
Upvotes: 1