OnCompletionListener. Interface definition for a callback to be invoked when playback of a media source has completed.
To check if audio is playing with JavaScript, we can use the paused property of the audio element. const isPlaying = (audElem) => { return !
You can use the MediaPlayer class and add a Completion listener to be activated when the sound finishes playing
MediaPlayer mp = MediaPlayer.create(this,Uri.parse("android.resource://emad.app/raw/seven_chimes"));
mp.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
performOnEnd();
}
});
mp.start();
Not working with broadcast receiver but this is what worked for my current project using Kotlin to track when the audio file has finished playing.
playButton.setOnClickListener {
if (isPlaying) {
pauseSound()
}else {
playSound()
}
mediaPlayer.setOnCompletionListener {
playButton.text = "Play"
isPlaying = false
}
}
isPlaying is boolean, I will explain more if someone is confused. Hope it helps someone else in the future. Happy coding!
try using service to play the music.. after it play once, then stop your service and you can add your program on the onDestroy() service method.. hope it helps :)
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