Oncompletion Isn't Being Called When I Would Expect It To
Solution 1:
mediaPlayer.start();
mediaPlayer.setOnCompletionListener(newOnCompletionListener()
{
@OverridepublicvoidonCompletion(MediaPlayer arg0)
{
Log.v("Tag", "Completed");
}
});
This snippet works fine. The only difference is the "@Override" and I'm not sure if the "@Override" has effect on the code.
Solution 2:
On my experience, the listener is not triggered on some devices :/
Solution 3:
I had this problem as well. It has nothing to do with the Override annotation.
I set the listener before I had configured a Visualizer. I moved the setOnCompletionListener()
to after I had accessed the MediaPlayer for the visualizer - this solved my problem. Make sure the method is called at the latest stage.
Solution 4:
I had to make a separate class to get it working. No amount of overriding worked.
privateclassSoundtrackPlayerListenerimplementsMediaPlayer.OnCompletionListener{
publicvoidonCompletion(MediaPlayer mp) {
//completion code here
}
}
Solution 5:
I and a couple of other students experienced the same problem in our mobile-apps course.
I'm not sure what the problem is but to us it seems like a bug with the emulator. On some linux machines the OnCompletionEvent didn't fire at all. On ones mac the Event fired in the application but not in the unittests.
Both (application and unittest) worked correctly if executed on a real device instead of the emulator.
The AVD we were using was the Samsung Galaxy Tab (android2.2 api8)
Post a Comment for "Oncompletion Isn't Being Called When I Would Expect It To"