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

实现原理: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) {}
}

  • 11
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值