Skip to contentSkip to navigationSkip to topbar
Rate this page:
On this page

Configuring Audio, Video Input and Output devices - Android


(warning)

Warning

This page is for reference only. We are no longer onboarding new customers to Programmable Video. Existing customers can continue to use the product until December 5, 2024(link takes you to an external page).
We recommend migrating your application to the API provided by our preferred video partner, Zoom. We've prepared this migration guide(link takes you to an external page) to assist you in minimizing any service disruption.

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.


Selecting a specific Video Input

selecting-a-specific-video-input page anchor

CameraCapturer

cameracapturer page anchor

The CameraCapturer provides video frames via the Camera API(link takes you to an external page) for a LocalVideoTrack from a given CameraCapturer.CameraSource.


_15
// Share your camera
_15
CameraCapturer cameraCapturer = new CameraCapturer(context, CameraSource.FRONT_CAMERA);
_15
LocalVideoTrack localVideoTrack = LocalVideoTrack.create(context, true, cameraCapturer);
_15
VideoView primaryVideoView = (VideoView) findViewById(R.id.local_video);
_15
_15
// Mirror front camera
_15
primaryVideoView.setMirror(true);
_15
_15
// Render camera to view
_15
localVideoTrack.addSink(primaryVideoView);
_15
_15
// Switch the camera source
_15
CameraSource cameraSource = cameraCapturer.getCameraSource();
_15
cameraCapturer.switchCamera();
_15
primaryVideoView.setMirror(cameraSource == CameraSource.BACK_CAMERA);

The Camera2Capturer provides video frames via the Camera 2 API(link takes you to an external page) for a LocalVideoTrack from a given camera ID.


_19
// Get the device camera IDs
_19
CameraManager cameraManager =
_19
(CameraManager) cameraCapturerActivity.getSystemService(Context.CAMERA_SERVICE);
_19
String[] cameraIds = cameraManager.getCameraIdList();
_19
_19
// This example uses the first Camera ID but applications can make their own decisions
_19
// about which Camera ID to use
_19
String cameraId = cameraIds[0];
_19
_19
// Share your camera
_19
Camera2Capturer camera2Capturer = new Camera2Capturer(context, cameraId, camera2Listener);
_19
LocalVideoTrack localVideoTrack = LocalVideoTrack.create(context, true, camera2Capturer);
_19
_19
// Render camera to a view
_19
VideoView primaryVideoView = (VideoView) findViewById(R.id.local_video);
_19
localVideoTrack.addSink(primaryVideoView);
_19
_19
// Switch the camera source from the first camera ID to the second camera ID
_19
camera2Capturer.switchCamera(cameraIds[1]);

For more details and other best practices capturing video from the camera capturers, please reference the Video Android Quickstart(link takes you to an external page).


Managing Audio With AudioSwitch

managing-audio-with-audioswitch page anchor

The Twilio Video Android SDK does not officially support audio device management. Please use AudioSwitch(link takes you to an external page) to manage audio focus and audio devices in your application.


Rate this page: