audio_session icon indicating copy to clipboard operation
audio_session copied to clipboard

Flutter : ❗️Issue: Mic is not activating after resuming the recording after iOS phone/voip call interruption – AVFAudio error -10868

Open navin-zignuts opened this issue 7 months ago • 3 comments

Platform: iOS Flutter version: 3.29.3

Packages used: record: ^6.0.0 audio_session: ^0.2.1

:white_check_mark: Expected Behaviour

  • Microphone Availability Check
    • Before starting or resuming recording, check if the microphone is already in use by another app.
    • If unavailable, display a dialog: “Microphone is currently in use by another application.”
  • Background Recording Support
    • Allow ongoing recordings to continue even when the app is sent to the background, ensuring persistent audio capture.
  • Automatic Interruption Handling
    • Phone/VOIP Call Interruption: Automatically pause recording when a phone or VOIP (e.g., WhatsApp, Teams) call is received or ongoing.
    • System Focus Modes:
      • Pause recording if the system is in a focus mode (like Do Not Disturb) and the microphone is not available.
      • Resume recording by user manually should only resume if mic is available.
      • Resume automatically if interruption ends.
  • Auto Resume Recording
    • Automatically resume recording once the interruption (call or focus mode) ends, maintaining the session seamlessly.

🔁 Steps to Reproduce the Issue

  1. Start recording in the app (orange mic indicator appears)
  2. Receive an incoming Teams call (recording continues)
  3. Decline the Teams call (recording automatically pauses due to interruption handling)
  4. Attempt to resume recording (microphone works briefly then fails)
  5. Pause recording manually
  6. Attempt to resume recording again (error -10868 appears)

Below are the configurations we set for initialise the session

await _session.configure(
        AudioSessionConfiguration(
          // iOS configuration for recording continuously when the another app starts recording
          avAudioSessionCategory: AVAudioSessionCategory.playAndRecord,
          avAudioSessionSetActiveOptions: AVAudioSessionSetActiveOptions.notifyOthersOnDeactivation,
          avAudioSessionCategoryOptions: AVAudioSessionCategoryOptions.mixWithOthers |
              AVAudioSessionCategoryOptions.allowBluetooth |
              AVAudioSessionCategoryOptions.allowBluetoothA2dp |
              AVAudioSessionCategoryOptions.allowAirPlay,
          avAudioSessionMode: AVAudioSessionMode.defaultMode,

          // androidAudioAttributes: const AndroidAudioAttributes(
          //   contentType: AndroidAudioContentType.speech,
          //   flags: AndroidAudioFlags.audibilityEnforced,
          //   usage: AndroidAudioUsage.voiceCommunication,
          // ),
          androidAudioFocusGainType: AndroidAudioFocusGainType.gainTransient,
          androidWillPauseWhenDucked: false,
        ),
      );

Requesting Focus for Microphone

 try {
      return await _session.setActive(
        true,
        avAudioSessionSetActiveOptions: AVAudioSessionSetActiveOptions.notifyOthersOnDeactivation,
      );
    } catch (e) {
      debugPrint("AUDIO SESSION error: ${e.toString()}");
      return false;
    }

Here how we are handling the interruptions from other apps

 Future<void> _handleAudioInterruptions() async {
    _recordInterruptionSubscription =
        _session.interruptionEventStream.listen((event) async {
          if (event.begin) {
                // here pause recording
          } else {
                // here trying to resume the recording 
          }
        });
  }

Workaround Tried

  • Manually deactivating and reactivating the session.
  • Reinitializing the audio recorder instance.
  • Adding a longer delay before resuming.
  • Re-requesting focus with setActive(true).

❓ Questions Is there any iOS-specific workaround for resuming the mic after a declined VoIP call? Is this expected behaviour in iOS or an edge case of audio session state management?

navin-zignuts avatar May 01 '25 13:05 navin-zignuts

I'm afraid I can't offer specific advice how to use the iOS APis, except to read the documentation for iOS and/or ask an iOS-specific question on StackOverflow (since this plugin simply provides a shallow wrapper around the native APIs).

ryanheise avatar May 01 '25 14:05 ryanheise

Thank you, @ryanheise, for your suggestion. I went through the iOS documentation and tried several approaches, but unfortunately, none of them worked as expected.

navin-zignuts avatar May 02 '25 06:05 navin-zignuts

@navin-zignuts, any update on this? Facing a similar issue.

richanshah avatar Jun 16 '25 12:06 richanshah