title: precision of Android MediaPlayer seekTo
body: <p>I have a number of mp3 files that I use with Android <em>MediaPlayer</em> to play from certain offsets.</p>
  
  <p>Using <em>seekTo()</em> seems to stop at correct location. <em>player.getCurrrentPosition()</em> returns the correct offset, but in some cases the real position is off for as much as 200 ms. The files are about 3 minutes worth of recording and the incorrect offsets seem to appear at the end. Of some of the files.</p>
  
  <p>I have the same effect either trying with Android 4.0.3 device or 4.3 emulator.</p>
  
  <p>Anybody has experience with "finetuning" <em>MediaPlayer</em> offsets? Any experience why <em>MediaPlayer</em> might not be working correctly with some files? They are all CBR, stereo, some have sampling frequency 22050, some 44100, different bitrates.</p>
  
  <p>I'm setting the offsets from another program and saving to mp3 tags, then in case of doubt verifying manually using <em>Audacity</em>. <em>Audacity</em> agrees with my estimate of what the correct offset is, <em>MediaPlayer</em> seems to disagree.</p>
  
  <p>I'm aware that I could use <em>AudioTrack</em> with raw sound files and have a better control, however it might be impractical as there are many mp3 files, so using raw sound data will make pretty large application or many large data files. </p>
  
  <p>The code is nothing fancy:</p>
  
  <pre><code>player.seekTo(start);
  player.start();
  CountDownTimer timer = new CountDownTimer(length, 100) {
  
      @Override
      public void onTick(long millisUntilFinished) {
          if (player!=null) setInt(R.id.nLocation, player.getCurrentPosition());
      }
  
      @Override
      public void onFinish() {
          if (player!=null) {
              if (player.isPlaying()) {
                  player.pause();
              }
              setInt(R.id.nLocation, player.getCurrentPosition());
              player.stop();
              player.release();
              player = null;
          }
      }
  };
  timer.start();
  </code></pre>