Skip to content Skip to sidebar Skip to footer

Android SeekBar SetProgress Is Causing My MediaPlayer To Skip

I'm trying to use a SeekBar to display both the length of a track played by a MediaPlayer class and to enable seeking within the track. Seeking within the track works well. However

Solution 1:

I think the problem is that when you call the setProgress(), the onProgressChanged event is fired.

The listener (OnSeekBarChangeListener) have a method public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser). Here you should test if the listener was fired by a user action or from code. In your case, the fromUser variable should be false.

public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
    if(fromUser){
           player.seekTo(x);
        }
        else{
         // the event was fired from code and you shouldn't call player.seekTo()
        }
}

Post a Comment for "Android SeekBar SetProgress Is Causing My MediaPlayer To Skip"