android无法在通信过程中从摄像头切换到屏幕共享webrtc

0aydgbwb  于 2021-07-06  发布在  Java
关注(0)|答案(0)|浏览(649)

我正在开发android应用程序,并在openvidu上使用webrtc。我有屏幕共享和相机共享工作。但只有这两种方法中的任何一种在同一个对等连接中起作用。我无法在它们之间切换。默认情况下,当建立连接时,相机将被共享,点击一个按钮,我应该能够在不断开现有连接的情况下共享屏幕。然而,这不是发生在我的情况。它不会在点击按钮时发布屏幕。它变成空白。
如果有人在相机和共享屏幕之间进行过切换,请帮助我。提前谢谢。

public VideoTrack MakeCameraSettingsReady() {
            final EglBase.Context eglBaseContext = EglBase.create().getEglBaseContext();
            PeerConnectionFactory peerConnectionFactory = this.sessionManager.getPeerConnectionFactory();

            // create AudioSource
            AudioSource audioSource = peerConnectionFactory.createAudioSource(new MediaConstraints());
            this.audioTrack = peerConnectionFactory.createAudioTrack("101", audioSource);

            surfaceTextureHelper = SurfaceTextureHelper.create("CaptureThread", eglBaseContext);
            // create VideoCapturer
            videoCapturer = createVideoCapturer();

            //MediaConstraints constraints = new MediaConstraints();

            VideoSource videoSource = peerConnectionFactory.createVideoSource(videoCapturer.isScreencast());
            localVideoTrack = peerConnectionFactory.createVideoTrack("100", videoSource);
            videoCapturer.initialize(surfaceTextureHelper, context, videoSource.getCapturerObserver());
            videoCapturer.startCapture(720, 1280, 30);

            return localVideoTrack;
        }

        public VideoTrack MakeScreenCaptureReady() {
            final EglBase.Context eglBaseContext = EglBase.create().getEglBaseContext();
            PeerConnectionFactory peerConnectionFactory = this.sessionManager.getPeerConnectionFactory();

            // create AudioSource
            AudioSource audioSource = peerConnectionFactory.createAudioSource(new MediaConstraints());
            this.audioTrack = peerConnectionFactory.createAudioTrack("101", audioSource);

            surfaceTextureHelper = SurfaceTextureHelper.create("CaptureThread", eglBaseContext);
            // create VideoCapturer
            screenCapturerAndroid = (ScreenCapturerAndroid) createScreenCapturer();

            //MediaConstraints constraints = new MediaConstraints();

            VideoSource videoSource = peerConnectionFactory.createVideoSource(screenCapturerAndroid.isScreencast());
            localVideoTrack = peerConnectionFactory.createVideoTrack("100", videoSource);
            screenCapturerAndroid.initialize(surfaceTextureHelper, context, videoSource.getCapturerObserver());
            screenCapturerAndroid.startCapture(720, 1280, 30);

            return localVideoTrack;
        }

当我点击按钮共享屏幕时,我使用以下代码:

private fun stopCameraShare(){
            videoCapturerAndroid?.stopCapture()
            localRenderer.dispose()
            localVideoView.release()
            localVideoView.clearImage()
            stream?.removeTrack(localVideoTrack)
            localVideoTrack.dispose()
        }

    private fun shareScreen(){
            stopCameraShare()
            val mediaProjectionManager = activity!!.getSystemService(Context.MEDIA_PROJECTION_SERVICE) as MediaProjectionManager
            startActivityForResult(mediaProjectionManager.createScreenCaptureIntent(), 29)
        }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (requestCode == SCREEN_RECORD_REQUEST_CODE) {
            if (resultCode == RESULT_OK) {
                //Start screen recording
                mResultCode = resultCode
                mResultData = data

                runOnUiThread {
                    screenCaptureVideoTrack = mLiveSessionViewModel!!.localParticipant?.MakeScreenCaptureReady()
                    mLiveSessionViewModel!!.localParticipant?.screenCaptureVideoTrack = screenCaptureVideoTrack
                }
            }
        }
    }

我尝试过的参考资料:如何在视频/音频通话中远程共享屏幕?
https://github.com/jeffiano/screensharertc
https://chromium.googlesource.com/external/webrtc/+/b75f2541c942e2f35c3b7d7003ed17504176ced1/webrtc/api/android/java/src/org/webrtc/screencapturerandroid.java
webrtc-在通信过程中更改视频流
最终,我试图找到一种在交流过程中添加/删除跟踪的方法。谢谢您!

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题