startCapture method

  1. @override
Future<void> startCapture()

Called by start before this track is marked active.

Implementation

@override
Future<void> startCapture() async {
  await super.startCapture();
  if (lkPlatformSupportsExplicitAudioRecordingStart()) {
    // Recording can start before any policy push (pre-connect audio,
    // pre-join mic). Hand native the resolved Dart policy first — cache-only
    // while the engine is idle — so the session is not left to the native
    // built-in preset.
    await AudioManager.instance.ensureAppleAudioSessionPolicy();
    try {
      // Match Swift: start the ADM before publishing so capture-time audio
      // processing options are applied before WebRTC opens the microphone.
      await Native.startLocalRecording(currentOptions.processing.toMap());
    } on PlatformException catch (error) {
      // Missing microphone permission or an audio session that does not
      // permit recording are not audio processing failures, so they surface
      // as their own exception types.
      throw audioEngineExceptionFrom(error) ??
          track_options.AudioProcessingException(
            _audioProcessingFailureReason(error.code),
            error.message ?? '',
          );
    }
  }
}