Skip to content

Commit

Permalink
Merge pull request #401 from bbjay/manage-audio-session
Browse files Browse the repository at this point in the history
manageAudioSession option for IosRecordConfig
  • Loading branch information
llfbandit authored Oct 9, 2024
2 parents c8091ad + f31fe8d commit d25e64c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
2 changes: 2 additions & 0 deletions record_darwin/darwin/Classes/RecordConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ struct IosConfig {
#if os(iOS)
extension IosConfig {
let audioCategories: [AVAudioSession.CategoryOptions]
let manageAudioSession: Bool

init(map: [String: Any]) {
let comps = map["audioCategories"] as? String
Expand All @@ -99,6 +100,7 @@ extension IosConfig {
}
}
self.audioCategories = options ?? []
self.manageAudioSession = map["manageAudioSession"] as? Bool ?? true
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ class RecorderFileDelegate: NSObject, AudioRecordingFileDelegate, AVAudioRecorde
func start(config: RecordConfig, path: String) throws {
try deleteFile(path: path)

try initAVAudioSession(config: config)
if config.iosConfig?.manageAudioSession ?? true {
try initAVAudioSession(config: config)
}

let url = URL(fileURLWithPath: path)

Expand Down
10 changes: 8 additions & 2 deletions record_platform_interface/lib/src/types/record_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,19 @@ class IosRecordConfig {
/// Constants that specify optional audio behaviors.
/// https://developer.apple.com/documentation/avfaudio/avaudiosession/categoryoptions
final List<IosAudioCategories> audioCategories;
/// Manage the shared AVAudioSession (defaults to `true`).
/// Set this to false if another plugin is already managing the AVAudioSession.
/// If false, audioCategories config will have no effect.
final bool manageAudioSession;

const IosRecordConfig({
this.audioCategories = const [IosAudioCategories.defaultToSpeaker, IosAudioCategories.allowBluetooth, IosAudioCategories.allowBluetoothA2DP]
this.audioCategories = const [IosAudioCategories.defaultToSpeaker, IosAudioCategories.allowBluetooth, IosAudioCategories.allowBluetoothA2DP],
this.manageAudioSession = true,
});
Map<String, dynamic> toMap() {
return {
"audioCategories": audioCategories.map((e) => e.name).join(',')
"audioCategories": audioCategories.map((e) => e.name).join(','),
"manageAudioSession": manageAudioSession,
};
}

Expand Down

0 comments on commit d25e64c

Please sign in to comment.