Skip to contentSkip to navigationSkip to topbar
On this page

Configuring Audio, Video Input and Output devices - Android


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.

1
// Share your camera
2
CameraCapturer cameraCapturer = new CameraCapturer(context, CameraSource.FRONT_CAMERA);
3
LocalVideoTrack localVideoTrack = LocalVideoTrack.create(context, true, cameraCapturer);
4
VideoView primaryVideoView = (VideoView) findViewById(R.id.local_video);
5
6
// Mirror front camera
7
primaryVideoView.setMirror(true);
8
9
// Render camera to view
10
localVideoTrack.addSink(primaryVideoView);
11
12
// Switch the camera source
13
CameraSource cameraSource = cameraCapturer.getCameraSource();
14
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.

1
// Get the device camera IDs
2
CameraManager cameraManager =
3
(CameraManager) cameraCapturerActivity.getSystemService(Context.CAMERA_SERVICE);
4
String[] cameraIds = cameraManager.getCameraIdList();
5
6
// This example uses the first Camera ID but applications can make their own decisions
7
// about which Camera ID to use
8
String cameraId = cameraIds[0];
9
10
// Share your camera
11
Camera2Capturer camera2Capturer = new Camera2Capturer(context, cameraId, camera2Listener);
12
LocalVideoTrack localVideoTrack = LocalVideoTrack.create(context, true, camera2Capturer);
13
14
// Render camera to a view
15
VideoView primaryVideoView = (VideoView) findViewById(R.id.local_video);
16
localVideoTrack.addSink(primaryVideoView);
17
18
// 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.

Need some help?

Terms of service

Copyright © 2024 Twilio Inc.