Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MediaPlayer onCompletion is not being called accurately

In my app i have created an audio player (only WAV files) using MediaPlayer API. But the player doesn't give callback to onCompletion Listener everytime. Sometimes it gives callback but not everytime. I am doing some audio processing on wav file , like insertion and overwriting.

Is it because any missing in audio header? Why it doesn't give callback when the playback is completed?

like image 377
Raneez Ahmed Avatar asked Jun 21 '13 06:06

Raneez Ahmed


3 Answers

Make sure that the headers of file is set correctly. If somethings in header is missing callback to the onCompletion may not occur.

If mediaplayer is playing a .wav file, seeking may happen correctly but a jerking will be there . So when the playingback completes there will be a differecnce of 0-1000 ms between total duration of file and onCompletion respectively. So if such a situation comes you should guess that as onColmpletion and do what you wanted. Thats a bit tricky way to get the onCompletion.

I faced the same problem while playing a .wav file with the mediaplayer. This is not a good way to solve this issue, but I tackled the same problem like this when i was having the same situation. Hope this will help you too in some ways.

like image 95
Sreedev Avatar answered Oct 16 '22 13:10

Sreedev


It seems you have to call setOnCompletionListener AFTER calling start(). Take a look here: https://stackoverflow.com/a/19555480/1860130

Worked for me.

like image 38
bernardo.g Avatar answered Oct 16 '22 13:10

bernardo.g


In order to get the onCompletion() function called you should disable looping with a call mediaPlayer.setLooping(false);

like image 1
Hack06 Avatar answered Oct 16 '22 11:10

Hack06