cocos creator(2.4.7版本) videoplayer 可以在上层添加UI控件()

2023-12-31 14:42:32

实现原理:cocos本身在平台中属于view,所以可以把videoplyer放在底层,以达到目标。

Cocos2dxVideoHelper.java
 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.setZOrderOnTop(true);
        videoView.setZOrderOnTop(false);// 修改为
        videoView.setVideoViewEventListener(videoEventListener);
    }
AppActivity.java
public Cocos2dxGLSurfaceView onCreateView() {
        Cocos2dxGLSurfaceView glSurfaceView = new Cocos2dxGLSurfaceView(this);
        // TestCpp should create stencil buffer
//        glSurfaceView.setEGLConfigChooser(5, 6, 5, 0, 16, 8);// 修改前
        glSurfaceView.setEGLConfigChooser(8, 8, 8, 8, 16, 8);// 修改后
        glSurfaceView.getHolder().setFormat(PixelFormat.RGBA_8888);// 修改后
        glSurfaceView.setZOrderMediaOverlay(true);// 修改后
        SDKWrapper.getInstance().setGLSurfaceView(glSurfaceView, this);


        return glSurfaceView;
    }
Cocos2dxVideoView.java
当控件处于最上层,但是由于video触摸吞噬,控件依然不可点击的。

 @Override
    public boolean onTouchEvent(MotionEvent event) {
        if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_UP) {
            this.sendEvent(EVENT_CLICKED);
        }
        return false;// true->改为false
    }
// 摄像机的背景color修改

const {ccclass, property} = cc._decorator;

@ccclass
export default class videoScene extends BaseScene {


    @property({displayName:"Camera",type:cc.Camera})
    camera : cc.Camera = null;

    @property({displayName:"直播",type:cc.VideoPlayer})
    videoplayer : cc.VideoPlayer = null;


    onLoad () {
        super.onLoad();
        this.camera.backgroundColor = new cc.Color(0, 0, 0, 0);
    }

    start () {
            this.videoplayer.resourceType = cc.VideoPlayer.ResourceType.REMOTE;
            this.videoplayer.remoteURL = 'http://benchmark.cocos2d-x.org/cocosvideo.mp4';
            this.videoplayer.isFullscreen = true;
            this.videoplayer.play();
    }

    // update (dt) {}
}

文章来源:https://blog.csdn.net/erweimac/article/details/135315435
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。