我想使用unity native方法调用mediaplayer setOnCompletionListener,如下所示:
mp.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
Log.i(LOGTAG, "onComplete hit");
mp.stop();
mp.release();
}
});
我知道我可以把上面的代码放在android上,然后生成jar,然后把它放到Unity项目中。但我不想那样,我喜欢
AndroidJavaObject mediaPlayer = new AndroidJavaObject("android/media/MediaPlayer");
IntPtr setSurfaceMethodId = AndroidJNI.GetMethodID(mediaPlayer.GetRawClass(),"setSurface","(Landroid/view/Surface;)V");
jvalue[] parms = new jvalue[1];
parms[0] = new jvalue();
parms[0].l = androidSurface;
AndroidJNI.CallVoidMethod(mediaPlayer.GetRawObject(), setSurfaceMethodId, parms);
mediaPlayer.Call("setDataSource", filePath);
答案 0 :(得分:0)
我已经解决了我的问题:
public class CompletionCallback:AndroidJavaProxy {
public CompletionCallback()
:base("android.media.MediaPlayer$OnCompletionListener") {
}
void onCompletion(AndroidJavaObject mp) {
CommonUtil.showToast("finish");
}
}
使用AndroidJavaProxy