摄像机ID对于前置摄像头为1,对于后置摄像头为0。 好吧,我写了一些代码来使用两个摄像头,但是当我录制并在最终视频中更换摄像头时,当我更换摄像头时视频停止播放... 有什么建议吗?
代码如下:
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.DEFAULT);
mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
mMediaRecorder.setVideoEncodingBitRate(1000000);
mMediaRecorder.setAudioEncodingBitRate(16);
mMediaRecorder.setAudioSamplingRate(44100);
mMediaRecorder.setVideoFrameRate(30);
mMediaRecorder.setAudioSamplingRate(16000);
mMediaRecorder.setVideoSize(imageDimension.getWidth(), imageDimension.getHeight());
mMediaRecorder.setOutputFile(getFilePath());
mMediaRecorder.setOrientationHint(90);
mMediaRecorder.prepare();
setupMediaRecorder();
SurfaceTexture surfaceTexture = textureView.getSurfaceTexture();
surfaceTexture.setDefaultBufferSize(imageDimension.getWidth(), imageDimension.getHeight());
Surface recordSurface = mMediaRecorder.getSurface();
Surface previewSurface = new Surface(surfaceTexture);
captureRequestBuilder = cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_RECORD);
captureRequestBuilder.addTarget(recordSurface);
captureRequestBuilder.addTarget(previewSurface);
cameraDevice.createCaptureSession(Arrays.asList(previewSurface,recordSurface), new CameraCaptureSession.StateCallback() {
@Override
public void onConfigured(@NonNull CameraCaptureSession cameraCaptureSession) {
try {
cameraCaptureSession.setRepeatingRequest(captureRequestBuilder.build(), null, null);
} catch (CameraAccessException e) {
e.printStackTrace();
}
}
@Override
public void onConfigureFailed(@NonNull CameraCaptureSession cameraCaptureSession) {
}
}, null);
} catch (IOException e) {
e.printStackTrace();
} catch (CameraAccessException e) {
e.printStackTrace();
}
}
如何录制两台相机并在视频播放过程中不停停地更改它们?
非常感谢您提供任何答案。