I want to start a video realtime session with the ...
# ask-ai
m
I want to start a video realtime session with the back camera rather than the front camera. Change this code. func setCamera(enabled: Bool) async throws { guard let device = AVCaptureDevice.devices().first(where: { $0.facingPosition == .back }) ?? AVCaptureDevice .devices().first else { throw NSError(domain: "CameraError", code: -1, userInfo: [NSLocalizedDescriptionKey: "No camera available"]) } try await room.localParticipant.setCamera( enabled: enabled, captureOptions: CameraCaptureOptions( device: device, dimensions: Dimensions(width: cameraDimensions.height, height: cameraDimensions.width) ) ) }
t
Thanks for reaching out, Rishabh. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hey! If you want to start a video session using the back camera in LiveKit, you can easily do that with the
CameraCaptureOptions
class. Here’s a quick way to update your code:
Copy code
func setCamera(enabled: Bool) async throws {
    let captureOptions = CameraCaptureOptions(position: .back)

    try await room.localParticipant.setCamera(
        enabled: enabled,
        captureOptions: captureOptions
    )
}
This will make sure the back camera is the one that starts up for your video session. If you run into any issues or have more questions, just let me know—I’m here to help! Sources: multicam/multicam/ContentView.swift | Sources/LiveKit/Types/Options/RoomOptions.swift