In this guide we'll show you how to configure Audio, Video input and output devices from your Twilio Video Rooms API application. Taking advantage of the ability to control input and output devices lets you build a better end user experience.
The CameraCapturer
provides video frames via the Camera API for a LocalVideoTrack
from a given CameraCapturer.CameraSource
.
1// Share your camera2CameraCapturer cameraCapturer = new CameraCapturer(context, CameraSource.FRONT_CAMERA);3LocalVideoTrack localVideoTrack = LocalVideoTrack.create(context, true, cameraCapturer);4VideoView primaryVideoView = (VideoView) findViewById(R.id.local_video);56// Mirror front camera7primaryVideoView.setMirror(true);89// Render camera to view10localVideoTrack.addSink(primaryVideoView);1112// Switch the camera source13CameraSource cameraSource = cameraCapturer.getCameraSource();14cameraCapturer.switchCamera();15primaryVideoView.setMirror(cameraSource == CameraSource.BACK_CAMERA);
The Camera2Capturer
provides video frames via the Camera 2 API for a LocalVideoTrack
from a given camera ID.
1// Get the device camera IDs2CameraManager cameraManager =3(CameraManager) cameraCapturerActivity.getSystemService(Context.CAMERA_SERVICE);4String[] cameraIds = cameraManager.getCameraIdList();56// This example uses the first Camera ID but applications can make their own decisions7// about which Camera ID to use8String cameraId = cameraIds[0];910// Share your camera11Camera2Capturer camera2Capturer = new Camera2Capturer(context, cameraId, camera2Listener);12LocalVideoTrack localVideoTrack = LocalVideoTrack.create(context, true, camera2Capturer);1314// Render camera to a view15VideoView primaryVideoView = (VideoView) findViewById(R.id.local_video);16localVideoTrack.addSink(primaryVideoView);1718// Switch the camera source from the first camera ID to the second camera ID19camera2Capturer.switchCamera(cameraIds[1]);
For more details and other best practices capturing video from the camera capturers, please reference the Video Android Quickstart.
The Twilio Video Android SDK does not officially support audio device management. Please use AudioSwitch to manage audio focus and audio devices in your application.