How to control media player with SeekBar

1.2k Views Asked by At

I am trying to control media player with seekbar, but whenever i do tap on seekbar its reached at the end of seekbar, see my code below:

          seekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

              @Override
              public void onStopTrackingTouch(SeekBar seekBar) {

              }

              @Override
              public void onStartTrackingTouch(SeekBar seekBar) {

              }

                  @Override
                  public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {                
                      if(mediaPlayer != null && fromUser){
                          mediaPlayer.seekTo(progress * 1000);
                      }
                  }
          });

what i am missing ? where i am doing mistake ? where i have to make changes in my code ?

1

There are 1 best solutions below

1
On BEST ANSWER

Progress bar returns correct position already. You don't need to multiply it by 1000. This should solve the issue.

@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {                
    if(mediaPlayer != null && fromUser){
        mediaPlayer.seekTo(progress);
    }
}