关于cocos2dx在android上视频始终置顶显示,无法上层添加单元的解决方案
由于cocos2dx在android上播放视频使用的是原生view,和cocos的mGLSurfaceView属于同层次的view,且调用videoView.setZOrderOnTop(true);一直置顶
所以无法通过简单的在cocos层添加单元解决
解决方案如下:
Cocos2dxVideoHelper.java的_createVideoView函数添加如下代码
private void _createVideoView(int index) { Cocos2dxVideoView videoView = new Cocos2dxVideoView(mActivity,index); sVideoViews.put(index, videoView); FrameLayout.LayoutParams lParams = new FrameLayout.LayoutParams( FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT); mLayout.addView(videoView, lParams); videoView.setZOrderMediaOverlay(true); videoView.setOnCompletionListener(videoEventListener); mTextView = new TextView(mActivity); FrameLayout.LayoutParams param_text = new FrameLayout.LayoutParams( FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT, Gravity.CENTER); int layoutHeight = mLayout.getHeight(); String heightStr = new String(); heightStr += layoutHeight; Log.e("zh", heightStr); param_text.setMargins(0, layout.Height/2 - 80, 0, 0); mLayout.addView(mTextView, param_text); mTextView.setTextColor(Color.argb(255, 255, 255, 255)); mTextView.setTextSize(20); }
videoView.setZOrderMediaOverlay(true)在网上的说法是
Control whether the surface view's surface is placed on top of another regular surface view in the window (but still behind the window itself). This is typically used to place overlays on top of an underlying media surface view.
大概意思是:控制这个surfaceView是否被放在另一个普通的surfaceView上面(但是仍然在窗口之后)。这个函数通常被用来将覆盖层至于一个多媒体层上面。
这个函数必须在窗口被添加到窗口管理器之前设置。
然后下面就添加一个TextView在Video层上方,就可以正常显示出来了

浙公网安备 33010602011771号