nananabatman nananabatman - 29 days ago 8
Android Question

MediaPlayer doesn't start when CountDownTimer is finished

I have a

CountDownTimer
like this:

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();


Variables
tic1
,
tic2
y
ticExp
type is
MediaPlayer
:

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);


When I execute
onFinish
method, the MediaPlayer
ticExp
should be played, but this doesn't occur.

I tested write
ticExp.start()
in method
onTick
and this works, so the file is not corrupted or something like this.
I don't have idea why in
onTick
method works, but in
onFinish
no.
(But the others sentences of code in
onFinish
are executed without problems)

Definitively, I want that
ticExp
will be played in
onFinish
method.

Sorry for my English. Thanks.

Answer Source

You are doing ticExp.reset(); after ticExp.start(); in onFinish(), That means you are actually starting and also resetting(making it idle). Just remove ticExp.reset(); in onFinish().

For the Complete State of MediaPlayer, you can refer this

And one more thing, Your else condition in onTick method will never execute.