我知道这是一个常见问题,但是此堆栈跟踪显示其他问题。你可以看到,即使setDisplay(holder)
在里面被调用,surfaceCreated
它仍然会抛出IllegalArgumentException
。这也不是一个罕见的例外,昨天在约 3,000,000 次剪辑视图中发生了约 125,000 次。我可以向您保证,它也mCurrentPlayer
已正确初始化。
表面创建:
@Override
public void surfaceCreated(SurfaceHolder holder) {
mIsSurfaceCreated = true;
mCurrentPlayer.setDisplay(holder);
}
表面销毁:
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
mIsSurfaceCreated = false;
// Could be called after player was released in onDestroy.
if (mCurrentPlayer != null) {
mCurrentPlayer.setDisplay(null);
}
}
堆栈跟踪:
java.lang.IllegalArgumentException: The surface has been released
at android.media.MediaPlayer._setVideoSurface(Native Method)
at android.media.MediaPlayer.setDisplay(MediaPlayer.java:660)
at com.xxx.xxx.view.VideoPlayerView.surfaceCreated(VideoPlayerView.java:464)
at android.view.SurfaceView.updateWindow(SurfaceView.java:543)
at android.view.SurfaceView.access$000(SurfaceView.java:81)
at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:169)
at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:590)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1644)
at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2505)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:4945)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
关于还有什么可能出错的任何想法?是否SurfaceHolder
可能会破坏后台线程上的表面,然后等待主线程(当前被 占用surfaceCreated
)完成它的块,然后才能调用surfaceDestroyed
主线程(我什至认为锁无法修复)?还有什么?
更新——深入研究后,我发现了导致“表面已被释放”的原因:
android_view_Surface_getSurface
可以在这里找到哪些参考资料:
这就是我缺乏 C++ 知识的痛处,它看起来像是试图锁定表面,如果不能,返回的表面将是null
. 一旦返回为null
,IllegalArgumentException
将被抛出。