c 2 c 2 - 1 year ago 38
Android Question

Audio interrupted when updating Android seebar while playing Media Player

I am developing an app that plays music from raw music files and it updates seekbar once every second while the

media player
is playing. However, this is interrupting audio each time the seekbar is updated through Runnable. I've tried using Sound Pool (from here) or creating new Thread suggested by other posts but the issue still exists. Should I be using service instead?

The following code snippet is run from a ListFragment. Thanks.

mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
updateProgress = false;

updateProgress = true;

updateRunnableHandler = new Handler();
mUpdateRunnable = new Runnable() {
public void run() {
if (updateProgress) {
updateRunnableHandler.postDelayed(mUpdateRunnable, 1000);

updateRunnableHandler.postDelayed(mUpdateRunnable, 1000);

c 2 c 2
Answer Source

Found the issue. The code needs to check if the onProgressChanged event handled by seekbar's setOnSeekBarChangeListener is from the user or not.

    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
        if (fromUser) {