title: Androids MediaPlayer plays video every second time activity enters
body: <p>I'm writing application in which one of the activities would able to play video files. I record the videos but then when trying to play trouble starts. Activity starts and plays the video fine for the first time. Then I press back button, go back to previous activity, select video (same or other) and video playing activity enters again, all the views (buttons, seekbar etc) shows, but video doesn't show. I go back again, select the video, open video playing activity and video plays fine again. So it plays every second time. I tried to debug but couldn't find what the problem is and any help would be much appreciated. Activity code is below and logCat output from eclipse is also below.</p>
  
  <pre><code>public class FightPlayerActivity extends Activity implements OnSeekBarChangeListener, SurfaceHolder.Callback, OnPreparedListener {
  
      private MediaPlayer mp=null;
      private SeekBar seekBar;
  
      private String filePath;
  
      @Override
      public void onCreate(Bundle savedInstanceState)
      {
          super.onCreate(savedInstanceState);
          Toast.makeText(this,"Create ", 2000).show();
  
          setContentView(R.layout.fight_player);
  
          filePath=getIntent().getStringExtra("filename");
          filePath=Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM)+"/FightAll_BJJ_Scoring/"+filePath;
  
          Toast.makeText(this,filePath, 2000).show();
          // seek bar
  
          seekBar=(SeekBar) findViewById(R.id.seek_bar);
          seekBar.setOnSeekBarChangeListener(this);
          try {
              SurfaceView sv=(SurfaceView) findViewById(id.video_preview);
  
              SurfaceHolder sh=sv.getHolder();
              sh.addCallback(this);
  
              sh.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
  
          } catch (IllegalArgumentException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          } catch (SecurityException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          } catch (IllegalStateException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }      
      }
  
      public void surfaceChanged(SurfaceHolder holder, int format, int width,
              int height) {
          // TODO Auto-generated method stub
  
      }
  
      public void onStop(View view)
      {
          super.onStop();
  
          mp.stop();
          mp.reset();
          mp.release();
      }
  
      public void onStart(View view)
      {
          super.onStart();
  
      }
  
      public void stop(View view)
      {
          mp.stop();
      }
  
      public void pause(View view)
      {
          mp.pause();
      }
  
      public void play(View view)
      {
          mp.start();
      }
  
      public void surfaceCreated(SurfaceHolder holder) {
  
          try {
              mp=new MediaPlayer();
              mp.setDataSource(filePath);
              mp.setDisplay(holder);  
              mp.setOnPreparedListener(this);
              mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
              mp.prepare();
  
          } catch (IllegalStateException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          } catch (IOException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          } 
      }
  
  
      public void surfaceDestroyed(SurfaceHolder holder) {
          // TODO Auto-generated method stub
  
      }
  
      public void onPrepared(MediaPlayer mediaplayer) {
           mp.start(); 
           seekBar.setMax(mp.getDuration());
      }
  
      public void onProgressChanged(SeekBar sb,int progress,boolean fromUser)
      {
          //Toast.makeText(this, progress, 2000).show();
          mp.seekTo(progress);
      }
  
      public void onStartTrackingTouch(SeekBar seekBar) {
          // TODO Auto-generated method stub
          onProgressChanged(seekBar,seekBar.getProgress(),true);
      }
  
      public void onStopTrackingTouch(SeekBar seekBar) {
          // TODO Auto-generated method stub
  
   }  
  </code></pre>
  
  <p>and log below:</p>
  
  <pre><code>08-19 18:26:39.325: E/MediaPlayer(7057): message received msg=200, ext1=1, ext2=44
  08-19 18:26:39.325: W/MediaPlayer(7057): info/warning (1, 44)
  08-19 18:26:39.325: E/MediaPlayer(7057): callback application
  08-19 18:26:39.325: E/MediaPlayer(7057): back from callback
  08-19 18:26:39.325: E/MediaPlayer(7057): message received msg=1, ext1=0, ext2=0
  08-19 18:26:39.325: E/MediaPlayer(7057): callback application
  08-19 18:26:39.325: E/MediaPlayer(7057): back from callback
  08-19 18:26:39.361: E/MediaPlayer(7057): message received msg=5, ext1=176, ext2=144
  08-19 18:26:39.361: E/MediaPlayer(7057): callback application
  08-19 18:26:39.365: E/MediaPlayer(7057): back from callback
  08-19 18:26:39.380: I/MediaPlayer(7057): Info (1,44)
  08-19 18:26:45.661: E/MediaPlayer(7057): message received msg=200, ext1=1, ext2=44
  08-19 18:26:45.661: W/MediaPlayer(7057): info/warning (1, 44)
  08-19 18:26:45.661: E/MediaPlayer(7057): callback application
  08-19 18:26:45.661: E/MediaPlayer(7057): back from callback
  08-19 18:26:45.661: E/MediaPlayer(7057): message received msg=1, ext1=0, ext2=0
  08-19 18:26:45.661: E/MediaPlayer(7057): callback application
  08-19 18:26:45.661: E/MediaPlayer(7057): back from callback
  08-19 18:26:45.708: I/MediaPlayer(7057): Info (1,44)
  08-19 18:26:45.779: W/IMediaDeathNotifier(7057): media server died
  08-19 18:26:45.779: E/MediaPlayer(7057): message received msg=100, ext1=100, ext2=0
  08-19 18:26:45.779: E/MediaPlayer(7057): error (100, 0)
  08-19 18:26:45.779: E/MediaPlayer(7057): callback application
  08-19 18:26:45.779: E/MediaPlayer(7057): back from callback
  08-19 18:26:45.779: E/MediaPlayer(7057): message received msg=100, ext1=100, ext2=0
  08-19 18:26:45.779: E/MediaPlayer(7057): error (100, 0)
  08-19 18:26:45.779: E/MediaPlayer(7057): callback application
  08-19 18:26:45.779: E/MediaPlayer(7057): back from callback
  08-19 18:26:45.779: W/Camera(7057): Camera server died!
  08-19 18:26:45.786: E/MediaPlayer(7057): Error (100,0)
  08-19 18:26:45.790: E/MediaPlayer(7057): Error (100,0)
  </code></pre>