// Enable camera
await call.setCameraEnabled(enabled: true);
// Disable camera
await call.setCameraEnabled(enabled: false);
// Enable camera with specific constraints
await call.setCameraEnabled(
enabled: true,
constraints: const CameraConstraints(
facingMode: FacingMode.environment,
mirrorMode: MirrorMode.off,
),
);
Camera Configuration
The Stream Video SDK provides comprehensive camera configuration capabilities, allowing you to control various aspects of the camera during video calls. From basic operations like enabling/disabling the camera to advanced features like zoom and focus control, the SDK offers an intuitive interface for managing camera functionality.
Before attempting to access the user’s camera, ensure the appropriate permissions are set in both the iOS plist
file and Android Manifest. You can read more about permissions in installation section.
Basic Camera Operations
Enable/Disable Camera
Control whether the camera is active during a call:
Camera Position Control
Switch between front and rear cameras:
// Set to front camera
await call.setCameraPosition(CameraPosition.front);
// Set to back camera
await call.setCameraPosition(CameraPosition.back);
// Flip camera (toggles between front and back)
await call.flipCamera();
Video Input Device Management
Select and configure specific camera devices:
// Set a specific video input device
await call.setVideoInputDevice(device);
// Get current camera device
var currentCamera = call.state.value.videoInputDevice;
Advanced Camera Features
Zoom Control
Adjust the camera zoom level programmatically:
// Set zoom level (1.0 = no zoom, higher values = more zoom)
await call.setZoom(zoomLevel: 2.0);
Focus and Exposure Control
Control camera focus and exposure points:
// Set focus to a specific point on the screen
// Point coordinates are relative to the video view (0.0 to 1.0)
await call.focus(focusPoint: Point(0.5, 0.5)); // Center of the screen
// Auto focus (no specific point)
await call.focus();
Platform-Specific Features
iOS Multitasking Camera Access
For iOS devices, you can control whether the camera remains accessible during multitasking:
// Enable multitasking camera access (iOS only)
await call.setMultitaskingCameraAccessEnabled(true);
// Disable multitasking camera access (iOS only)
await call.setMultitaskingCameraAccessEnabled(false);
You don’t need to explicitly call this method, as the SDK will handle it automatically when the muteVideoWhenInBackground
option is set to false in StreamVideoOptions
.
Camera State Management
Accessing Camera State
You can access the current camera state through the call state:
// Get current camera device
var camera = call.state.value.videoInputDevice;
// Check if camera is enabled
var isCameraEnabled = call.state.value.localParticipant?.isVideoEnabled ?? false;
Error Handling
All camera methods return a Result
type for proper error handling:
final result = await call.setCameraEnabled(enabled: true);
result.fold(
success: (success) {
print('Camera enabled successfully');
},
failure: (failure) {
print('Failed to enable camera: ${failure.error.message}');
},
);