title: audio and seekbar in android
body: <p>i created audio activity with seekbar, it was played but i have problem when seekbar in progress there is cutting each 1 second in sound because i used (Thread.sleep).</p>
  
  <p>i check another solution in Internet, all codes i checked were use same concept.</p>
  
  <p>this is my code</p>
  
  <pre><code>public class PlaySounds extends Activity implements Runnable {
  SeekBar seeksounds;
  MediaPlayer mp;
  Handler handler = new Handler();
  int id;
  public boolean isFileExists(String fileName) {
      try {
          File myFile = new File(fileName);
          FileInputStream fIn = new FileInputStream(myFile);
          BufferedReader myReader = new BufferedReader(new InputStreamReader(fIn));
          return true;
      } catch (Exception e) {
          return false;
      }
  }
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.playsounds);
      seeksounds = (SeekBar) findViewById(R.id.seeksounds);
      getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
  
          String path = Environment.getExternalStorageDirectory().toString() + "/dowload/splash.mp3";
          if (isFileExists(path)) {
              mp = new MediaPlayer();
              try {
                  mp.setDataSource(path);
                  mp.prepare();
                  mp.start();
                  int maxD = mp.getDuration();
                  int currentD = mp.getCurrentPosition();
                  seeksounds.setMax(maxD);
                  seeksounds.setProgress(currentD);
                  new Thread(this).start();
                  seeksounds.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
  
                      @Override
                      public void onProgressChanged(SeekBar arg0, int progress,
                              boolean arg2) {
                          mp.seekTo(progress);
                          seeksounds.setProgress(progress);
  
                      }
  
                      @Override
                      public void onStartTrackingTouch(SeekBar seekBar) {
                          // TODO Auto-generated method stub
  
                      }
  
                      @Override
                      public void onStopTrackingTouch(SeekBar seekBar) {
                          // TODO Auto-generated method stub
  
                      }
  
                  });
              } catch (Exception e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              } 
          }
  }
  @Override
  public void onBackPressed() {
      // TODO Auto-generated method stub
      super.onBackPressed();
      mp.release();
  }
  
  @Override
  public void run() {
      int currentPosition= 0;
      int total = mp.getDuration();
      while (mp!=null &amp;&amp; currentPosition&lt;total) {
          try {
              Thread.sleep(1000);
              currentPosition= mp.getCurrentPosition();
              seeksounds.setProgress(currentPosition);
          }  catch (Exception e) {
              return;
          }            
  
      }
  
  }
  </code></pre>
  
  <p>}</p>