I have some Android code to stream an audio file from the internet and play the stream after 10 seconds.
I am using a SeekBar to view the buffering status and playing status. I want to play the audio starting from the middle of the buffered stream. For that, I move the SeekBar point to the middle, but I cannot play the audio from the middle; it will go back and start from the beginning. How can I get the seeked position and how can I play the audio from that particular position?
Here is my SeekBar code. How can I make this code use the OnSeekBarChangeListener properly?
seekbar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) {
// TODO Auto-generated method stub
if (arg2 && mediaPlayer.isPlaying()) {
//myProgress = oprogress;
arg1=mediaPlayer.getCurrentPosition();
mediaPlayer.seekTo(arg1);
}
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
});
arg1=mediaPlayer.getCurrentPosition();
mediaPlayer.seekTo(arg1);
You are forcing the player to seek to the current position, and not to the positon retuned by the Seekbar
Remove the line: arg1=mediaPlayer.getCurrentPosition();
and it should work. Of course after MediaPlayer.prepare()
set SeekBar.setMax(MediaPlayer.getDuration())
, so seeking will be accurate.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With