Camera
Some VideoKit components (like Recorder
or StreamHost
) will automatically
open a connection with the camera sensor available on the device.
We offer control over some core camera features through the Camera
protocol and its listeners.
You can typically access the camera object from the parent component, for example:
let camera = recorder.camera // from recorder module
let camera = streamHost.camera // from live stream module
Direction
You can choose which sensor is active by changing the camera direction
value:
camera.direction = .front // switch to front
camera.direction = .back // switch to back
camera.toggleDirection() // switch to the other one
You can observe the direction value by implementing CameraObserver
and registering it with camera.addObserver()
:
func cameraDirectionChanged(direction: CameraDirection) {
// Handle change
}
Flash
You can control the flash behavior by changing the camera flash
value:
camera.flash = .on // turn torch on
camera.flash = .off // turn it on
camera.toggleFlash() // switch to the other one
You can observe the flash value by implementing CameraObserver
and registering it with camera.addObserver()
:
func cameraFlashChanged(flash: CameraFlash) {
// Handle change
}
Zoom
You can control the sensor zoom by changing the camera zoom
value. The minimum value is 1
and it means no zoom.
You can observe the zoom value by implementing CameraObserver
and registering it with camera.addObserver()
:
func cameraZoomChanged(zoom: CGFloat) {
// Handle change
}