Menu

Rate this page:

Thanks for rating this page!

We are always striving to improve our documentation quality, and your feedback is valuable to us. How could this documentation serve you better?

Configuring Audio, Video Input and Output devices

In this guide we’ll show you how to configure Audio routes and Video inputs in your Twilio Video application.

Selecting a specific Video Input

The TVICameraCapturer class captures from a TVICameraCaptureSource, and provides frames to a TVILocalVideoTrack. You can check what camera sources are available on your device by using the class method TVICameraCapturer.availableSources().

Add selected video source to local track

// The default initializer will succeed if the front camera is available.

if let camera = TVICameraCapturer(source: .frontCamera),
    let videoTrack = TVILocalVideoTrack(capturer: camera) {

    // TVIVideoView is a TVIVideoRenderer and can be added to any TVIVideoTrack.
    let renderer = TVIVideoView(frame: view.bounds)

    // Add renderer to the video track
    videoTrack.addRenderer(renderer)

    self.localVideoTrack = videoTrack
    self.camera = camera
    self.view.addSubview(renderer)
} else {
    print("Couldn't create TVICameraCapturer or TVILocalVideoTrack")
}

// Select between the front and (wide) back camera.
func flipCamera() {
    if let camera = camera {
        if (camera.source == .frontCamera) {
            camera.selectSource(.backCameraWide)
        } else {
            camera.selectSource(.frontCamera)
        }
    }
}

Selecting specific Audio routes

Typically, the audio input & output route is chosen by the end user via Control Center. The TVIAudioOutput enumeration can override this configuration and it constrains the available route choices that the user sees in Control Center. Use the TVIAudioController.audioOutput property to choose a setting appropriate for your use case.

Note: In all cases the route configuration chosen must support full duplex audio, such as a bluetooth headset or conference speaker system.

Need some help?

We all do sometimes; code is hard. Get help now from our support team, or lean on the wisdom of the crowd browsing the Twilio tag on Stack Overflow.

Loading Code Sample...