title: click on back button and MediaPlayer crash Android
body: <p>For MediaPlayer I have referred <a href="http://www.androidhive.info/2012/03/android-building-audio-player-tutorial/" rel="nofollow">http://www.androidhive.info/2012/03/android-building-audio-player-tutorial/</a>.</p>
  
  <p>I have created activity for Media Player and it is having all the functionality like play, pause, next, previous, seekbar and also includes <code>OnCompletionListener</code>. All works excellent. But now I want that all should be managed by service.</p>
  
  <p>I have created MyService Class :</p>
  
  <pre><code>public class MusicPlayerService extends Service {
  
      MediaPlayer mp;
      String fullStreamUrl;
  
      @Override
      public IBinder onBind(Intent arg0) {
  
          return null;
      }
  
      @Override
      public void onCreate() {
          super.onCreate();
          mp = new MediaPlayer();
      }
  
      @Override
      public int onStartCommand(Intent intent, int flags, int startId) {
          if (intent != null) {
              fullStreamUrl = intent.getStringExtra("fullStreamUrl");
              // Log.d("url", "Geturl:-  " + fullStreamUrl);
          }
  
          try {
              mp.reset();
              mp.setDataSource(fullStreamUrl);
              mp.prepareAsync();
              mp.start();
              mp.setLooping(true);
          } catch (IllegalArgumentException e) {
              // TODO Auto-generated catch block 
              e.printStackTrace();
          } catch (IllegalStateException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          } catch (IOException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
          return 0;
      }
  
      @Override
      public void onDestroy() {
          mp.release();
          super.onDestroy();
      }
  }
  </code></pre>
  
  <p>How to manage all functionality using service and currentsongIndex.
  Thanks. Please clear my doubt. I am so confused.</p>