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

Configuring Audio, Video Input and Output devices - Android 5.x


(warning)

Warning

This documentation 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, 2026(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.addRenderer(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.addRenderer(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).


Selecting a specific Audio input

selecting-a-specific-audio-input page anchor

The Twilio Video Android SDK does not officially support switching the AudioSource and just defaults to the native Android API MediaRecorder.AudioSource.VOICE_COMMUNICATION(link takes you to an external page)


Selecting a specific Audio output

selecting-a-specific-audio-output page anchor

Using the AudioManager(link takes you to an external page) class provided by Android, you can specify if audio is routed through the headset or speaker.


_10
// Get AudioManager
_10
AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
_10
_10
// Route audio through speaker
_10
audioManager.setSpeakerphoneOn(true);
_10
_10
// Route audio through headset
_10
audioManager.setSpeakerphoneOn(false);


Rate this page: