How do I use AndroidJavaProxy to add a listener to a MediaPlayer

I have an Android application that has a functional video player, and I want to use the AndroidJavaProxy to add an OnInfoListener.

class OnInfoListener : AndroidJavaProxy
{
	public OnInfoListener() : base("android.media.MediaPlayer$OnInfoListener") {}
	void onInfo(AndroidJavaObject mp, int what, int extra)
	{
	}
}

I already have an AndroidJavaObject called mediaPlayer which I am able to call to play/pause the video, so I then do this:

mediaPlayer.Call("setOnInfoListener", new OnInfoListener());

As soon as it reaches the point where this callback would be called it crashes the app out. I have tried to attach the debugger and trap the callback with mixed results, mostly it just crashes out.

I believe the callback comes from a different thread, is there any problem using AndroidJavaProxy with multiple threads?

Thanks

The reason Unity is crashing is because the return type of the listener declared does not match the return type of the listener required. Change:

void onInfo(AndroidJavaObject mp, int what, int extra)

to:

bool onInfo(AndroidJavaObject mp, int what, int extra)

and it will fix the problem. Unity matches the signature ignoring return type and then crashes if the return type signature doesn’t match.

It is also worth noting that these callbacks can be called from a separate thread and so things like file I/O can cause exceptions. Code executed within these callbacks must be thread safe.