英文:
CameraCapturer must be initialized before calling startCapture
问题
在在Android中实现WebRTC时遇到以下问题:
> Caused by: java.lang.RuntimeException: 在调用startCapture之前,必须初始化CameraCapturer。
build.gradle(:app)
dependencies {
......
implementation 'org.webrtc:google-webrtc:1.0.+'
......
}
// 导致问题的代码块:
private void getVideoSource() {
// isScreenCast = false
videoSource = peerConnectionFactory.createVideoSource(false);
surfaceTextureHelper = SurfaceTextureHelper.create(Thread.currentThread().getName(), rootEglBase.getEglBaseContext());
VideoCapturer videoCapturer = createCameraCapturer(new Camera1Enumerator(false));
localVideoTrack = peerConnectionFactory.createVideoTrack("200", videoSource);
localVideoTrack.addSink(local_renderer);
if(videoCapturer != null)
videoCapturer.startCapture(1000, 1000, 30); // <- 异常出现在这里
}
CameraCapturer已被弃用。现在有Camera1Capturer可用。
英文:
Facing this issue while implementing WebRTC in Android:
> Caused by: java.lang.RuntimeException: CameraCapturer must be initialized before calling startCapture.
build.gradle(:app)
dependencies {
......
implementation 'org.webrtc:google-webrtc:1.0.+'
......
}
// Chunk causing problem:
private void getVideoSource() {
// isScreenCast = false
videoSource = peerConnectionFactory.createVideoSource(false);
surfaceTextureHelper = SurfaceTextureHelper.create(Thread.currentThread().getName(), rootEglBase.getEglBaseContext());
VideoCapturer videoCapturer = createCameraCapturer(new Camera1Enumerator(false));
localVideoTrack = peerConnectionFactory.createVideoTrack("200", videoSource);
localVideoTrack.addSink(local_renderer);
if(videoCapturer != null)
videoCapturer.startCapture(1000,1000,30); // <- Here is the Exception
}
CameraCapturer is deprecated. There is Camera1Capturer now available.
答案1
得分: 3
> 在使用之前,您需要进行初始化
private void getVideoSource() {
VideoCapturer videoCapturer = createVideoCapturer();
VideoSource videoSource;
// 创建一个VideoSource实例
if (videoCapturer != null) {
SurfaceTextureHelper surfaceTextureHelper = SurfaceTextureHelper.create("CaptureThread", rootEglBase.getEglBaseContext());
videoSource = factory.createVideoSource(videoCapturer.isScreencast());
videoCapturer.initialize(surfaceTextureHelper, this, videoSource.getCapturerObserver());
}
localVideoTrack = factory.createVideoTrack("100", videoSource);
// 创建MediaConstraints - 用于指定视频和音频约束
audioConstraints = new MediaConstraints();
videoConstraints = new MediaConstraints();
// 创建一个AudioSource实例
audioSource = factory.createAudioSource(audioConstraints);
localAudioTrack = factory.createAudioTrack("101", audioSource);
if (videoCapturer != null) {
videoCapturer.startCapture(1024, 720, 30);
}
binding.localGlSurfaceView.setVisibility(View.VISIBLE);
// 最后,当我们的VideoRenderer准备好后,
// 可以将我们的渲染器添加到VideoTrack中。
localVideoTrack.addSink(binding.localGlSurfaceView);
}
英文:
> You need to initialise before you use it
private void getVideoSource() {
VideoCapturer videoCapturer = createVideoCapturer();
VideoSource videoSource;
//Create a VideoSource instance
if (videoCapturer != null) {
SurfaceTextureHelper surfaceTextureHelper = SurfaceTextureHelper.create("CaptureThread", rootEglBase.getEglBaseContext());
videoSource = factory.createVideoSource(videoCapturer.isScreencast());
videoCapturer.initialize(surfaceTextureHelper, this, videoSource.getCapturerObserver());
}
localVideoTrack = factory.createVideoTrack("100", videoSource);
//Create MediaConstraints - Will be useful for specifying video and audio constraints.
audioConstraints = new MediaConstraints();
videoConstraints = new MediaConstraints();
//create an AudioSource instance
audioSource = factory.createAudioSource(audioConstraints);
localAudioTrack = factory.createAudioTrack("101", audioSource);
if (videoCapturer != null) {
videoCapturer.startCapture(1024, 720, 30);
}
binding.localGlSurfaceView.setVisibility(View.VISIBLE);
// And finally, with our VideoRenderer ready, we
// can add our renderer to the VideoTrack.
localVideoTrack.addSink(binding.localGlSurfaceView);
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论