llfbandit / record

Audio recorder from microphone to a given file path. No external dependencies, MediaRecorder is used for Android an AVAudioRecorder for iOS.
https://pub.dev/packages/record
245 stars 203 forks source link

manageAudioSession option for IosRecordConfig #401

Closed bbjay closed 1 month ago

bbjay commented 2 months ago

Hi there,

I'm using this plugin alongside just_audio and audio_session plugins in my app. Because my players have to support audio route switching, I am using the audio_session plugin for it. With this setup, I ran into the following issues when recording on iOS:

The reason for this is that AudioRecorder.start() also configures the shared AVAudioSession and activates it, after I already have configured and activated it through audio_session. This re-activation can cause a delay in audio processing when recording and also explains the cancelation of an existing route change subscription. (On Android everything is working fine, since this plugin does not touch the AudioManager attributes)

With the added IosRecordConfig.manageAudioSession option set to false, I can circumvent these issues. It defaults to true, so no changes in default behavior.

May I also suggest a renaming of the IosRecordConfig.audioCategories field to audioCategoryOptions? Because the category, currently hardcoded to .playAndRecord, is a different property of the audio session. I think the IosRecordConfig addition has not been released yet, so no breaking change would be introduced.

llfbandit commented 1 month ago

Thanks for your contribution!