Switch Camera

How to Switch Cameras in Video Calls Using the 100ms SDK

With the 100ms SDK, you can switch between using the front and back camera for your video calls. To do so, you need to set the cameraFacing setting in the HMSVideoTrackSettings when building the trackSettings for the SDK. The following code demonstrates how to set the camera facing to the back:

var hmsSDK: HMSSDK? ... hmsSDK = HMSSDK.build { sdk in sdk.trackSettings = HMSTrackSettings.build { videoSettingsBuilder, audioSettingsBuilder in videoSettingsBuilder.cameraFacing = .back ... } }

How to toggle between cameras using 100ms SDK?

To toggle between the front and back cameras during a call, you can use the switchCamera method on the HMSLocalVideoTrack instance. The following code demonstrates how to toggle the camera:

if let localTrack = hmsSDK.localPeer?.videoTrack as? HMSLocalVideoTrack { localTrack.switchCamera() }

👀 To see a complete example of switching cameras in an iOS app using 100ms SDK, checkout our example project.

Have a suggestion? Recommend changes ->

Was this helpful?