Skip to content Skip to sidebar Skip to footer

When Seekbar Updating Android's Mediaplayer Video Is Not Smooth

I'm playing video via MediPlayer in my android application and have SeekBar displayed. Now I want this seeks bar to automatically update as the video progresses so it should automa

Solution 1:

Your major problem is in your onProgressChanged() method.

You are seeking to the specified position every time the seekBar progress changes, even when it is done programmatically. Which means that every time you call seekBar.setProgress(mp.getCurrentPosition()), onProgressChanged() will be fired.

So we change it to the following:

publicvoidonProgressChanged(SeekBar sb, int progress, boolean fromUser) {
    if (fromUser) {
        mp.seekTo(progress);
    }
}

That way it will only be fired when the user moves the seekBar.

Moreover, according to this answer, it would be better to replace your while(true) loop with:

public void run() {
    seekBar.setProgress(mp.getCurrentPosition());
    if (mp.getCurrentPosition() < mp.getDuration()) {
        seekBar.postDelayed(this, MILLISECONDS);
    }

}

Post a Comment for "When Seekbar Updating Android's Mediaplayer Video Is Not Smooth"