Skip to content

Instantly share code, notes, and snippets.

@vivek1794
Created May 1, 2017 12:58
Show Gist options
  • Save vivek1794/b9f2cdfbd4a7295efe17092ccb54ee81 to your computer and use it in GitHub Desktop.
Save vivek1794/b9f2cdfbd4a7295efe17092ccb54ee81 to your computer and use it in GitHub Desktop.
Method to create and return a video capturer for WebRTC using Camera 1 API
private VideoCapturer createVideoCapturer() {
VideoCapturer videoCapturer;
videoCapturer = createCameraCapturer(new Camera1Enumerator(false));
return videoCapturer;
}
private VideoCapturer createCameraCapturer(CameraEnumerator enumerator) {
final String[] deviceNames = enumerator.getDeviceNames();
// Trying to find a front facing camera!
for (String deviceName : deviceNames) {
if (enumerator.isFrontFacing(deviceName)) {
VideoCapturer videoCapturer = enumerator.createCapturer(deviceName, null);
if (videoCapturer != null) {
return videoCapturer;
}
}
}
// We were not able to find a front cam. Look for other cameras
for (String deviceName : deviceNames) {
if (!enumerator.isFrontFacing(deviceName)) {
VideoCapturer videoCapturer = enumerator.createCapturer(deviceName, null);
if (videoCapturer != null) {
return videoCapturer;
}
}
}
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment