initialize method
Initializes the camera on the device.
Throws a CameraException if the initialization fails.
Implementation
Future<void> initialize() async {
if (_isDisposed) {
return Future<void>.value();
}
try {
_creatingCompleter = Completer<void>();
final Map<String, dynamic>? reply =
await _channel.invokeMapMethod<String, dynamic>(
'initialize',
<String, dynamic>{
'cameraName': description.name,
'resolutionPreset': serializeResolutionPreset(resolutionPreset),
'streamingPreset':
serializeResolutionPreset(streamingPreset ?? resolutionPreset),
'enableAudio': enableAudio,
'enableAndroidOpenGL': androidUseOpenGL
},
);
if (reply == null) {
throw CameraException('invalid',
'Unable top communicate with the camera platform channel');
}
if (reply['textureId'] == null) {
throw CameraException('invalid', 'textureID is null');
}
_textureId = reply['textureId']!;
value = value.copyWith(
isInitialized: true,
previewSize: Size(
reply['previewWidth'].toDouble(),
reply['previewHeight'].toDouble(),
),
previewQuarterTurns: reply['previewQuarterTurns'],
);
} on PlatformException catch (e) {
throw CameraException(e.code, e.message ?? 'Unknown exception');
}
_eventSubscription = EventChannel(
'plugins.flutter.io/camera_with_rtmp/cameraEvents$_textureId')
.receiveBroadcastStream()
.listen(_listener);
_creatingCompleter.complete();
return _creatingCompleter.future;
}