🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
1.设定自定义采集 ~~~ private void setupLocalVideo(FrameLayout frameLayout,boolean top) { if(mTextureCamera == null){ mTextureCamera = new TextureCamera(this, 640, 480); mTextureCamera.setOnCaptureListener(new TextureCamera.OnCaptureListener() { @Override public int onTextureBufferAvailable(int textureId, byte[] buffer, int width, int height) { int newTexture = textureId; try { if (mhBeautyManager == null) { mhBeautyManager = new MHBeautyManager(getApplicationContext(),true); mhBeautyManager.setBeautyDataModel(BeautyDataModel.getInstance()); if (beautyViewHolder != null) { beautyViewHolder.setMhBeautyManager(mhBeautyManager); } }else{ if (mCameraFacing == Camera.CameraInfo.CAMERA_FACING_FRONT){ newTexture = mhBeautyManager.render10(textureId, width, height); }else{ newTexture = mhBeautyManager.render11(textureId, width, height); } } } catch (Exception e) { e.printStackTrace(); } return newTexture; } @Override public void onCapturerStarted() { Log.d(TAG, "onCapturerStarted() called"); } @Override public void onCapturerStopped() { Log.d(TAG, "onCapturerStopped() called"); } @Override public void onCameraSwitched(int facing, int orientation) { Log.d(TAG, "onCameraSwitched() called with: facing = [" + facing + "], orientation = [" + orientation + "]"); mCameraFacing = facing; } }); } mLocalView = new AgoraSurfaceView(VideoLineActivity.this); mLocalView.init(mTextureCamera.getEglContext()); mLocalView.setBufferType(MediaIO.BufferType.TEXTURE); mLocalView.setPixelFormat(MediaIO.PixelFormat.TEXTURE_2D); mLocalView.setZOrderOnTop(top); mLocalView.setZOrderMediaOverlay(top); frameLayout.addView(mLocalView); mRtcEngine.setLocalVideoRenderer(mLocalView); mRtcEngine.setVideoSource(mTextureCamera); mTextureCamera.onResume(); } ~~~ 2.切换大小屏的时候销毁资源 ~~~ mTextureCamera.onPause(); mTextureCamera.release(); mTextureCamera = null; mhBeautyManager.destroy(); mhBeautyManager = null; ~~~ 3. 设置本地渲染 大屏 ~~~ setupLocalVideo(video_chat_big,false); ~~~ 小屏 ~~~ setupLocalVideo(video_chat_small,true); ~~~