MediaPlayer.OnCompletionListener
in
Android Processing
•
2 years ago
Curious to know if anyone has used this successfully in their Android project yet?
Or if anyone can spot obvious errors (as I've mentioned several times, Classes and Objects are not my strong suite...)
I *think* I've managed to make the callback correctly, but it doesn't seem to be registering...
Here's my code:
- void startPlaying() {
- println("Starting File...");
- mPlayer = new MediaPlayer();
- playFileName = "sdcard/SonicDrift/" + playFileName;
- try {
- println("PLAYING " + playFileName);
- mPlayer.setDataSource(playFileName);
- mPlayer.setLooping(false);
- mPlayer.setWakeMode(getApplicationContext(), PowerManager.PARTIAL_WAKE_LOCK);
- mPlayer.prepare();
- mPlayer.start();
- mPlayer.setOnCompletionListener(mOnCompletionListener);
- }
- catch (IOException e) {
- println("prepare() failed");
- e.printStackTrace();
- }
- }
- public void setOnCompletionListener(OnCompletionListener listener) {
- mOnCompletionListener = listener;
- println("Listening...");
- }
- public void onCompletion(MediaPlayer mPlayer) {
- println("FINISHED...");
- stopPlaying();
- }
- void stopPlaying() {
- println("Stopping File...");
- mPlayer.release();
- mPlayer = null;
- }
And of course, I've imported
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
and declared
MediaPlayer mPlayer = null;
OnCompletionListener mOnCompletionListener;
...
I've noticed a few threads on Stack Overflow, etc that there was some issue of the callback NOT working with .3gp files (which some of mine are), but I've tested with mp3's and Wav's as well, and no dice...
Relevant Links:
android.media package
MediaPlayer class
Thanks in advance...
~ J
1