android - Continuous Audio Playback despite Orientation Change -


this question has been asked few times, none of answers have helped me solve problem i'm posting version of it.

i'm creating app plays list of songs through service. problem got null exception error mediaplayer after rotate device. can see below, first start , bind service in onresume method. likewise, unbind , stop service in ondestroy method.


protected void onresume() {     if (playintent == null) {         playintent = new intent(mainactivity.this, mediaservice.class);   //       if (n < 0) {             startservice(playintent);             bindservice(playintent, mediaconnection, context.bind_auto_create);             log.d("check", "started service");   //      }     }      super.onresume(); } 

in service, set mediaplayer in service's oncreate method below. have few things in onstartcommand method (like creating notification show in action bar). return start_sticky in onstartcommand method.

unfortunately, said, when rotate device, null exception mediaplayer.

please help; i've been trying fix days.


static private mediaplayer player; private final ibinder musicbind = new mediabinder(); notification notification; private int playbackduration; static uri paths[][] = new uri[mainactivity.number_of_artists][mainactivity.number_of_tracks];  public void oncreate() {     // create service     super.oncreate();     player = new mediaplayer();     player.reset();     player.setlooping(true);     initmediaplayer();      log.d("check", "in service's oncreate method"); 


Comments