最近有个项目需要使用带麦克风的外置摄像头的方式采集音频和视频,webrtc默认是采用手机麦克风采集音频的,需要在创建peerConnectionFactory的时候进行设置。
//使用外置麦克风
JavaAudioDeviceModule.Builder admBuilder = JavaAudioDeviceModule.builder(this);
admBuilder.setAudioSource(MediaRecorder.AudioSource.MIC);
peerConnectionFactory = PeerConnectionFactory.builder()
.setVideoDecoderFactory(new DefaultVideoDecoderFactory(eglBase.getEglBaseContext()))
.setVideoEncoderFactory(new DefaultVideoEncoderFactory(eglBase.getEglBaseContext(), true, true))
.setAudioDeviceModule(admBuilder.createAudioDeviceModule())
.setOptions(options)
.createPeerConnectionFactory();