且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Android的搜索栏setProgress导致我的MediaPlayer跳过

更新时间:2023-12-05 23:12:04

我觉得问题是,当你调用setProgress(),该onProgressChanged事件。

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

监听器(OnSeekBarChangeListener)有一个方法 公共无效onProgressChanged(搜索栏搜索栏,INT进步,布尔FROMUSER)。在这里,你应该测试,如果听者被解雇由用户操作或code。 在你的情况下,FROMUSER变量应该是假的。

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()
        }
}