Forum Xamarin Xamarin.Android

MediaPlayer - how can I tell when it's finished?

kkhkkh USMember

The Recipe for using MediaPlayer to play a sound is nice & simple; works fine -- until I try to do a bit more with it.

I'd like to cleanly Release() the MediaPlayer when I'm done -- but I can't figure out how to tell when I'm done.

The most obvious seems to be to use SetOnCompletionListener(). It wants a callback function of type MediaPlayer.SetOnCompletionListener. Fine; I create such a function. But then Xamarin Studio says the callback needs to return a value. What value should my callback return? I haven't been able to cast an int or a bool to the proper type.

Another idea is to loop until CurrentPosition matches Duration, but Duration isn't implemented, it seems.

Any other ideas? Thanks for your help.

Sign In or Register to comment.