initialize method
Future<CameraMacOSArguments?>
initialize({
- String? deviceId,
- String? audioDeviceId,
- required CameraMacOSMode cameraMacOSMode,
- PictureFormat pictureFormat = PictureFormat.tiff,
- VideoFormat videoFormat = VideoFormat.mp4,
- PictureResolution resolution = PictureResolution.max,
- bool enableAudio = true,
- AudioFormat audioFormat = AudioFormat.kAudioFormatAppleLossless,
- AudioQuality audioQuality = AudioQuality.max,
- Torch toggleTorch = Torch.off,
- CameraOrientation orientation = CameraOrientation.orientation0deg,
- bool isVideoMirrored = true,
override
Call this method to initialize camera. If you implement the widget in your widget tree, this method is useless.
Implementation
@override
Future<CameraMacOSArguments?> initialize(
{
/// initialize the camera with a video device. If null, the macOS default camera is chosen
String? deviceId,
/// initialize the camera with an audio device. If null, the macOS default microphone is chosen
String? audioDeviceId,
/// Photo or Video
required CameraMacOSMode cameraMacOSMode,
/// format of the output photo
PictureFormat pictureFormat = PictureFormat.tiff,
/// format of the output photo
VideoFormat videoFormat = VideoFormat.mp4,
/// resolution of the output video/image
PictureResolution resolution = PictureResolution.max,
/// Enable Audio Recording
bool enableAudio = true,
/// Change the videos audio format type
AudioFormat audioFormat = AudioFormat.kAudioFormatAppleLossless,
AudioQuality audioQuality = AudioQuality.max,
/// Enable light
Torch toggleTorch = Torch.off,
/// Set camera orientation
CameraOrientation orientation = CameraOrientation.orientation0deg,
bool isVideoMirrored = true}) async {
try {
final Map<String, dynamic>? result =
await methodChannel.invokeMapMethod<String, dynamic>(
'initialize',
{
"deviceId": deviceId,
"audioDeviceId": audioDeviceId,
"type": cameraMacOSMode.index,
"enableAudio": enableAudio,
'resolution': resolution.name,
'quality': audioQuality.name,
'orientation': orientation.index * 90.0,
'isVideoMirrored': isVideoMirrored,
'torch': toggleTorch.index,
'pformat': pictureFormat.name,
'vformat': videoFormat.name,
'aformat': audioFormat.index,
},
);
if (result == null) {
throw FlutterError("Invalid args: invalid platform response");
}
if (result["error"] != null) {
throw result["error"];
}
isDestroyed = false;
List<Map<String, dynamic>> devicesList =
List.from(result["devices"] ?? [])
.map((e) => Map<String, dynamic>.from(e))
.toList();
List<CameraMacOSDevice> devices = [];
for (Map<String, dynamic> m in devicesList) {
CameraMacOSDevice device = CameraMacOSDevice.fromMap(m);
devices.add(device);
}
return CameraMacOSArguments(
textureId: result["textureId"],
size: Size(
result["size"]?["width"] ?? 0,
result["size"]?["height"] ?? 0,
),
devices: devices,
);
} catch (e) {
return Future.error(e);
}
}