Android SeekBar setProgress is causing my MediaPlayer to skip

前端 未结 1 1760
醉酒成梦
醉酒成梦 2020-12-29 08:44

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 wor

相关标签:
1条回答
  • 2020-12-29 09:11

    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()
            }
    }
    
    0 讨论(0)
提交回复
热议问题