Home » Android » java – Sound plays twice-Exceptionshub

java – Sound plays twice-Exceptionshub

Posted by: admin February 26, 2020 Leave a comment

Questions:

Hey there i m looking for solution for my current issue i m trying o play the mp3 music in my app and controlling it with a seekBar, i m hearing the sound twice it like a delay.

the MediaPlayer named musicPlayer and the seekBar named scrubseekBar

my code:

final SeekBar scrubseekBar = findViewById(R.id.scrubSeekBar);

        scrubseekBar.setMax(musicPlay.getDuration());

        new Timer().scheduleAtFixedRate(new TimerTask() {
            @Override
            public void run() {
                    scrubseekBar.setProgress(musicPlay.getCurrentPosition());
            }
        },0,1000);

        scrubseekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                    musicPlay.seekTo(progress);
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
                musicPlay.pause();

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
                musicPlay.start();

            }
        });
How to&Answers: