title: Handle the seekTo function of media player in android
body: <p>There is a video activity, I need to handle:</p>
  
  <p>1) when the first time enter the activity, get the position from intent and play the video</p>
  
  <p>2) keep the same position after rotate</p>
  
  <p>Here is the code to handle first requirement</p>
  
  <pre><code>@Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.video_full_screen);
      ButterKnife.bind(this);
  
      if (getIntent() != null) {
          video_url = getIntent().getStringExtra("video_url");
          pos = (int)getIntent().getLongExtra("time", 0);
      }
  
      player.setOnPreparedListener(this);
      player.setVideoURI(Uri.parse(video_url));
  }
  
  @Override
  public void onPrepared(MediaPlayer mp) {
      player.seekTo(pos);
      player.start();
  }
  </code></pre>
  
  <p>Here is the code to handle second requirement</p>
  
  <pre><code>@Override
      protected void onSaveInstanceState(Bundle outState)
      {
          outState.putInt("time", (int)player.getCurrentPosition());
          player.pause();
          super.onSaveInstanceState(outState);
      }
  
      @Override
      protected void onRestoreInstanceState(Bundle savedInstanceState)
      {
          int last_pos = savedInstanceState.getInt("time");
          player.seekTo(last_pos);
          player.start();
          super.onRestoreInstanceState(savedInstanceState);
      }
  </code></pre>
  
  <p>The problem is the handling is conflict to each other. </p>
  
  <p>If first time enter progess is 10s , when I play at e.g. 30s and rotate , it still go to 10s instead of 30s.</p>
  
  <p>It is caused by the seekTo(pos) at the onPrepared function but I can not remove that as it handle the first requirement.</p>
  
  <p>How to fix that? Thanks for helping.</p>