initialize method

  1. @override
Future<CameraMacOSArguments?> initialize({
  1. String? deviceId,
  2. String? audioDeviceId,
  3. required CameraMacOSMode cameraMacOSMode,
  4. PictureFormat pictureFormat = PictureFormat.tiff,
  5. VideoFormat videoFormat = VideoFormat.mp4,
  6. PictureResolution resolution = PictureResolution.max,
  7. bool enableAudio = true,
  8. AudioFormat audioFormat = AudioFormat.kAudioFormatAppleLossless,
  9. AudioQuality audioQuality = AudioQuality.max,
  10. Torch toggleTorch = Torch.off,
  11. CameraOrientation orientation = CameraOrientation.orientation0deg,
  12. 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);
  }
}