当surfaceview被破坏时,我的媒体播放器向前跳过几秒钟。 它是一个由2个片段组成的视频播放器。在每个片段中都是应该看到视频的表面视图。如果我在2个片段之间切换,我必须调用'mPlayer.setDisplay(surfaceHolder);'。否则视频将不会显示。但是有一个问题是玩家向前跳了几秒钟。原因是当调用方法surfaceDestroyed时,视频缓冲区被转储。根据{{3}}
我已经尝试过使用surfacetexture和textureview。 因此,我在mainActivity中声明了一个静态SurfaceTexture变量,当我在片段之间切换时,我保存了surfaceTexture。在切换之后,我将surfacetexture设置为textureview。
textureView.setSurfaceTexture(MainActivity.getSurfaceTexture());
当我第一次切换而不跳过或中断时,这甚至可以工作。但是当我第二次切换时抛出了一个runtimeexception ..
attachToContext: GLConsumer is already attached to a context
Shutting down VM
W/dalvikvm(8400): threadid=1: thread exiting with uncaught exception (group=0xa4d25b20)
FATAL EXCEPTION: main
Process: info.androidhive.slidingmenu, PID: 8400
java.lang.RuntimeException: Error during attachToGLContext (see logcat for details)
at android.graphics.SurfaceTexture.attachToGLContext(SurfaceTexture.java:215)
at android.view.GLES20TextureLayer.setSurfaceTexture(GLES20TextureLayer.java:86)
at android.view.HardwareRenderer$Gl20Renderer.setSurfaceTexture(HardwareRenderer.java:2221)
at android.view.TextureView.getHardwareLayer(TextureView.java:401)
at android.view.View.getDisplayList(View.java:13328)
at android.view.View.getDisplayList(View.java:13404)
at android.view.View.draw(View.java:14182)
at android.view.ViewGroup.drawChild(ViewGroup.java:3103)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2940)
at android.view.View.getDisplayList(View.java:13357)
at android.view.View.getDisplayList(View.java:13404)
at android.view.View.draw(View.java:14182)
at android.view.ViewGroup.drawChild(ViewGroup.java:3103)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2940)
at android.view.View.draw(View.java:14468)
at android.view.View.getDisplayList(View.java:13362)
at android.view.View.getDisplayList(View.java:13404)
at android.view.View.draw(View.java:14182)
at android.view.ViewGroup.drawChild(ViewGroup.java:3103)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2940)
at android.view.View.getDisplayList(View.java:13357)
at android.view.View.getDisplayList(View.java:13404)
at android.view.View.draw(View.java:14182)
at android.view.ViewGroup.drawChild(ViewGroup.java:3103)
at android.support.v4.widget.DrawerLayout.drawChild(DrawerLayout.java:804)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2940)
at android.view.View.getDisplayList(View.java:13357)
at android.view.View.getDisplayList(View.java:13404)
at android.view.View.draw(View.java:14182)
at android.view.ViewGroup.drawChild(ViewGroup.java:3103)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2940)
at android.view.View.getDisplayList(View.java:13357)
at android.view.View.getDisplayList(View.java:13404)
at android.view.View.draw(View.java:14182)
at android.view.ViewGroup.drawChild(ViewGroup.java:3103)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2940)
at android.view.View.draw(View.java:14468)
at com.android.internal.widget.ActionBarOverlayLayout.draw(ActionBarOverlayLayout.java:381)
at android.view.View.getDisplayList(View.java:13362)
at android.view.View.getDisplayList(View.java:13404)
at android.view.View.draw(View.java:14182)
at android.view.ViewGroup.drawChild(ViewGroup.java:3103)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2940)
at android.view.View.draw(View.java:14468)
at android.widget.FrameLayout.draw(FrameLayout.java:472)
at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:2326)
at android.view.View.getDisplayList(View.java:13362)
at android.view.View.getDisplayList(View.java:13404)
at android.view.HardwareRenderer$GlRenderer.buildDisplayList(HardwareRenderer.java:1570)
at android.view.HardwareRenderer$GlRenderer.draw(HardwareRenderer.java:1449)
at android.view.ViewRootImpl.draw(ViewRootImpl.java:2377)
at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2249)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1879)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:996)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5600)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
at android.view.Choreographer.doCallbacks(Choreographer.java:574)
at android.view.Choreographer.doFrame(Choreographer.java:544)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.
有人知道为什么要调用此异常吗?
答案 0 :(得分:0)
当您尝试附加到仍附加到其他视图的纹理时会发生这种情况。你必须等待视图分离。这将在onDetachedFromWindow()
电话中发生。我知道它并不理想(我们一直在努力解决共享表面的视图之间的同步问题),但这是我唯一能想到的,除非Android决定使这种情况不致命。
您可以考虑将对SurfaceTexture
的引用包装在一个跟踪它是否附加的类中(使用您对setSurfaceTexture()
和onDetachedFromWindow()
的调用并仅添加您的第二个视图一旦包裹的纹理知道它已经分离,就进入层次结构。