How do i use the OnCompletion listener for some music? I would like to press a button to go to another activity that plays some music and then goes back when the music playback is finished. I allready coded the other stuff. I just cant figure out how to use the OnCompletion listener?
OnCompletionListener. Interface definition for a callback to be invoked when playback of a media source has completed.
Start/Pause the playback: After loading the media file, you can start playing the media file by using the start() method. Similarly, you can pause the playing media file by using the pause() method. Stop the playback: You can stop playback by using the reset() method.
MediaPlayer Class in Android is used to play media files. Those are Audio and Video files. It can also be used to play audio or video streams over the network.
You should put the code that should be run when the music is completed in the OnCompletionListener
, for example:
mPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { public void onCompletion(MediaPlayer mp) { finish(); // finish current activity } });
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