0

I need save the MediaPlayer object on android screen rotatio.

But i not know can execute this action.

some people can help me?

2 Answers 2

1

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.

0

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;
}

}

1
  • it is incomplete and I can help you to complete this class, but first let me know you want to play something from local resources or from some server ? as you have written mp.setDataSource("74.222.1.197:13588"); but still i want to be sure whether you want to play resources from local files or files on some server.
    – Farooq
    Dec 28, 2012 at 15:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.