I had the same problem or something similar.
When I used mMediapPlayer.getCurrentPosition() in TimerTask to update the SeekBar, I heard sound problems like an echo, but actually the problem was not there.
The problem is that I also used the SeekBar OnSeekBarChangeListener for manual searching, but the update seekBar from TimerTask also caused a listener that made mp.seekTo(progress) , and this caused mp to return to this position again ..
I fixed it using the fromUser argument, as suggested here, to search only if seekBar changed manually.
Here is my sample code:
TimerTask:
public void initializeTimerTask() { mTimerTask = new TimerTask() { public void run() { int progress = mp.getCurrentPosition()/1000; runOnUiThread(new Runnable() { @Override public void run() { mSeekBar.setProgress(progress); tvDuration.setText(DateUtils.formatElapsedTime(progress)); } }); } }; }
LISTENER:
mSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { if(mp != null && fromUser){ mp.seekTo(progress * 1000); } } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } });
Moti Bartov
source share