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?
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.
It seems you have to call setOnCompletionListener AFTER calling start(). Take a look here: https://stackoverflow.com/a/19555480/1860130
Worked for me.
In order to get the onCompletion() function called you should disable looping with a call mediaPlayer.setLooping(false);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With