Skip to content Skip to sidebar Skip to footer

Mediaplayer.seekto() Does Not Work For Unbuffered Position

I use MediaPlayer for playing a single mp3 song from network. Data source is a HTTP URL. Let's assume we have following playing state. Song duration: 1:00 Current progress: 0:10 Cu

Solution 1:

I found a workaround for this problem:

First you create an OnBufferingUpdateListener:

MediaPlayer.OnBufferingUpdateListenerbufferingListener=newMediaPlayer.OnBufferingUpdateListener() {
    publicvoidonBufferingUpdate(MediaPlayer mp, int percent) {
        //code to increase your secondary seekbar
    }
};

Then in your seekbar event onProgressChanged do the following:

publicvoidonProgressChanged(SeekBar seekBar, int progress,
                boolean fromUser) {
    intsecondaryPosition= seekBar.getSecondaryProgress();
    if (progress > secondaryPosition)
        seekBar.setProgress(secondaryPosition);
}

With this you guarantee the user can't drag the progress bar to an unbuffered position (and also you see what's buffered).

Solution 2:

It has been fixed in Android 2.2 in some devices only as far as I know.

However Android 2.2 messes up with seeking to buffered posistion. Although a position is already buffered MediaPlayer sends a request to a server.

Solution 3:

It's probably related to the bug that's (referring to one of the comments) eventually fixed in 2.2 http://code.google.com/p/android/issues/detail?id=4124

Post a Comment for "Mediaplayer.seekto() Does Not Work For Unbuffered Position"