MediaPlayer does not play in CountDownTimer

1

I have a CountDownTimer as follows:

cuentaAtras = new CountDownTimer(mili, 1000) {

            public void onTick(long millisUntilFinished) {
                long seconds = millisUntilFinished / 1000;


                if (seconds  <= TIEMPO3){

                    if (tic1.isPlaying()){
                        tic1.stop();
                        tic2.start();
                    }

                } else if (seconds <= TIEMPO && seconds > TIEMPO2 + 10){
                    tic1.start();
                }
            }

            public void onFinish() {
                if (tic2.isPlaying())
                {
                    tic2.stop();
                }
                ticExp.start();

                tic1.reset();
                tic2.reset();
                ticExp.reset();

            }
        }.start();

The variables tic1 , tic2 and ticExp are of type MediaPlayer and I initialize them as follows:

 tic1 = MediaPlayer.create(getApplicationContext(), R.raw.tic1);
 tic1.setLooping(true);
 tic2 = MediaPlayer.create(getApplicationContext(), R.raw.tic3);
 tic2.setLooping(true);
 ticExp = MediaPlayer.create(getApplicationContext(), R.raw.exp);

The problem comes when the onFinish method is executed, since the ticExp should be reproduced, but that never happens.

I have tried putting it in the onTick method, and if it is playing, so it is discarded that the audio file is corrupted or something. I have no idea why in onTick it plays and in the onFinish it never gets heard. (But if you get to execute the other instructions, such as tic2 stop listening)

I hope to hear your suggestions to solve a problem that is giving me headaches. Thanks.

    
asked by cnbandicoot 15.08.2017 в 11:12
source

1 answer

1

The answer is that he executed the ticExp.reset() after ticExp.start() and did not give him time to run and reset it. I removed the ticExp.reset() line and it works now.

Response I received at StackOverflow .

    
answered by 23.08.2017 / 10:26
source