From 26a077b21b81e11f02a3317bb82c1698aff52eba Mon Sep 17 00:00:00 2001 From: Gustl22 Date: Tue, 4 Jul 2023 16:19:44 +0200 Subject: [PATCH 01/10] fix(ios)!: set default to `AVAudioSessionCategory.playback` --- .../test/global_audioplayers_test.dart | 1 - .../lib/src/api/audio_context.dart | 31 ++++++++++++++++++- .../lib/src/api/audio_context_config.dart | 4 ++- .../test/global_platform_test.dart | 1 - 4 files changed, 33 insertions(+), 4 deletions(-) diff --git a/packages/audioplayers/test/global_audioplayers_test.dart b/packages/audioplayers/test/global_audioplayers_test.dart index 6a4c9396d..1bd9f9d79 100644 --- a/packages/audioplayers/test/global_audioplayers_test.dart +++ b/packages/audioplayers/test/global_audioplayers_test.dart @@ -46,7 +46,6 @@ void main() { category: AVAudioSessionCategory.playback, options: [ AVAudioSessionOptions.mixWithOthers, - AVAudioSessionOptions.defaultToSpeaker ], ), ), diff --git a/packages/audioplayers_platform_interface/lib/src/api/audio_context.dart b/packages/audioplayers_platform_interface/lib/src/api/audio_context.dart index 8fc9bfe9c..d22907498 100644 --- a/packages/audioplayers_platform_interface/lib/src/api/audio_context.dart +++ b/packages/audioplayers_platform_interface/lib/src/api/audio_context.dart @@ -109,7 +109,6 @@ class AudioContextIOS { this.category = AVAudioSessionCategory.playback, this.options = const [ AVAudioSessionOptions.mixWithOthers, - AVAudioSessionOptions.defaultToSpeaker ], }); @@ -394,34 +393,64 @@ enum AVAudioSessionCategory { enum AVAudioSessionOptions { /// An option that indicates whether audio from this session mixes with audio /// from active sessions in other audio apps. + /// You can set this option explicitly only if the audio session category is + /// `playAndRecord`, `playback`, or `multiRoute`. + /// If you set the audio session category to `ambient`, the session + /// automatically sets this option. Likewise, setting the `duckOthers` or + /// `interruptSpokenAudioAndMixWithOthers` options also enables this option. + /// See: https://developer.apple.com/documentation/avfaudio/avaudiosession/categoryoptions/1616611-mixwithothers mixWithOthers, /// An option that reduces the volume of other audio sessions while audio from /// this session plays. + /// You can set this option only if the audio session category is + /// `playAndRecord`, `playback`, or `multiRoute`. + /// Setting it implicitly sets the `mixWithOthers` option. + /// https://developer.apple.com/documentation/avfaudio/avaudiosession/categoryoptions/1616618-duckothers duckOthers, /// An option that determines whether to pause spoken audio content from other /// sessions when your app plays its audio. + /// You can set this option only if the audio session category is + /// `playAndRecord`, `playback`, or `multiRoute`. Setting this option also + /// sets `mixWithOthers`. + /// See: https://developer.apple.com/documentation/avfaudio/avaudiosession/categoryoptions/1616534-interruptspokenaudioandmixwithot interruptSpokenAudioAndMixWithOthers, /// An option that determines whether Bluetooth hands-free devices appear as /// available input routes. + /// You can set this option only if the audio session category is + /// `playAndRecord` or `record`. + /// See: https://developer.apple.com/documentation/avfaudio/avaudiosession/categoryoptions/1616518-allowbluetooth allowBluetooth, /// An option that determines whether you can stream audio from this session /// to Bluetooth devices that support the Advanced Audio Distribution Profile /// (A2DP). + /// The system automatically routes to A2DP ports if you configure an app’s + /// audio session to use the `ambient`, `soloAmbient`, or `playback` + /// categories. + /// See: https://developer.apple.com/documentation/avfaudio/avaudiosession/categoryoptions/1771735-allowbluetootha2dp allowBluetoothA2DP, /// An option that determines whether you can stream audio from this session /// to AirPlay devices. + /// You can only explicitly set this option if the audio session’s category is + /// set to `playAndRecord`. + /// See: https://developer.apple.com/documentation/avfaudio/avaudiosession/categoryoptions/1771736-allowairplay allowAirPlay, /// An option that determines whether audio from the session defaults to the /// built-in speaker instead of the receiver. + /// You can set this option only when using the `playAndRecord` category. + /// See: https://developer.apple.com/documentation/avfaudio/avaudiosession/categoryoptions/1616462-defaulttospeaker defaultToSpeaker, /// An option that indicates whether the system interrupts the audio session /// when it mutes the built-in microphone. + /// If your app uses an audio session category that supports input and output, + /// such as `playAndRecord`, you can set this option to disable the default + /// behavior and continue using the session. + /// See: https://developer.apple.com/documentation/avfaudio/avaudiosession/categoryoptions/3727255-overridemutedmicrophoneinterrupt overrideMutedMicrophoneInterruption, } diff --git a/packages/audioplayers_platform_interface/lib/src/api/audio_context_config.dart b/packages/audioplayers_platform_interface/lib/src/api/audio_context_config.dart index 5466f6123..0b4fcaa97 100644 --- a/packages/audioplayers_platform_interface/lib/src/api/audio_context_config.dart +++ b/packages/audioplayers_platform_interface/lib/src/api/audio_context_config.dart @@ -121,7 +121,9 @@ class AudioContextConfig { return AudioContextIOS( category: respectSilence ? AVAudioSessionCategory.ambient - : AVAudioSessionCategory.playback, + : (forceSpeaker + ? AVAudioSessionCategory.playAndRecord + : AVAudioSessionCategory.playback), options: [AVAudioSessionOptions.mixWithOthers] + (duckAudio ? [AVAudioSessionOptions.duckOthers] : []) + (forceSpeaker ? [AVAudioSessionOptions.defaultToSpeaker] : []), diff --git a/packages/audioplayers_platform_interface/test/global_platform_test.dart b/packages/audioplayers_platform_interface/test/global_platform_test.dart index 9ba80dd18..0eede3195 100644 --- a/packages/audioplayers_platform_interface/test/global_platform_test.dart +++ b/packages/audioplayers_platform_interface/test/global_platform_test.dart @@ -89,7 +89,6 @@ void main() { 'category': 'playback', 'options': [ 'mixWithOthers', - 'defaultToSpeaker', ] }); }); From 5c75d57f52e4c29b5de041ee846f53fa2c4af1be Mon Sep 17 00:00:00 2001 From: Gustl22 Date: Tue, 4 Jul 2023 16:31:11 +0200 Subject: [PATCH 02/10] fix(ios)!: set default to `AVAudioSessionCategory.playback` --- packages/audioplayers_darwin/ios/Classes/AudioContext.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/audioplayers_darwin/ios/Classes/AudioContext.swift b/packages/audioplayers_darwin/ios/Classes/AudioContext.swift index f603b18e1..3452ca2fe 100644 --- a/packages/audioplayers_darwin/ios/Classes/AudioContext.swift +++ b/packages/audioplayers_darwin/ios/Classes/AudioContext.swift @@ -5,8 +5,8 @@ struct AudioContext { let options: [AVAudioSession.CategoryOptions] init() { - self.category = .playAndRecord - self.options = [.mixWithOthers, .defaultToSpeaker] + self.category = .playback + self.options = [.mixWithOthers] } init( From dc14ac7ff209e8ac50622749d5eded89eb6e2424 Mon Sep 17 00:00:00 2001 From: Gustl22 Date: Tue, 4 Jul 2023 16:53:04 +0200 Subject: [PATCH 03/10] fix: use defaults of native platform --- packages/audioplayers/test/global_audioplayers_test.dart | 9 +++++++-- .../main/kotlin/xyz/luan/audioplayers/AudioContext.kt | 2 +- .../lib/src/api/audio_context.dart | 6 ++++-- .../lib/src/api/audio_context_config.dart | 2 +- .../test/global_platform_test.dart | 4 ++-- 5 files changed, 15 insertions(+), 8 deletions(-) diff --git a/packages/audioplayers/test/global_audioplayers_test.dart b/packages/audioplayers/test/global_audioplayers_test.dart index 1bd9f9d79..2395ea82d 100644 --- a/packages/audioplayers/test/global_audioplayers_test.dart +++ b/packages/audioplayers/test/global_audioplayers_test.dart @@ -27,6 +27,11 @@ void main() { globalPlatform.clear(); }); + /// Note that the [AudioContextIOS.category] has to be + /// [AVAudioSessionCategory.playback] to default the audio to the receiver + /// (e.g. built-in speakers or BT-device, if connected). + /// If using [AVAudioSessionCategory.playAndRecord] the audio will come from + /// the earpiece unless [AVAudioSessionOptions.defaultToSpeaker] is used. test('set AudioContext', () async { await globalScope.setAudioContext(const AudioContext()); final call = globalPlatform.popLastCall(); @@ -35,9 +40,9 @@ void main() { call.value, const AudioContext( android: AudioContextAndroid( - isSpeakerphoneOn: true, + isSpeakerphoneOn: false, audioMode: AndroidAudioMode.normal, - stayAwake: true, + stayAwake: false, contentType: AndroidContentType.music, usageType: AndroidUsageType.media, audioFocus: AndroidAudioFocus.gain, diff --git a/packages/audioplayers_android/android/src/main/kotlin/xyz/luan/audioplayers/AudioContext.kt b/packages/audioplayers_android/android/src/main/kotlin/xyz/luan/audioplayers/AudioContext.kt index d17683dd7..a61b04405 100644 --- a/packages/audioplayers_android/android/src/main/kotlin/xyz/luan/audioplayers/AudioContext.kt +++ b/packages/audioplayers_android/android/src/main/kotlin/xyz/luan/audioplayers/AudioContext.kt @@ -19,7 +19,7 @@ data class AudioContextAndroid( ) { @SuppressLint("InlinedApi") // we are just using numerical constants constructor() : this( - isSpeakerphoneOn = true, + isSpeakerphoneOn = false, stayAwake = false, contentType = CONTENT_TYPE_MUSIC, usageType = USAGE_MEDIA, diff --git a/packages/audioplayers_platform_interface/lib/src/api/audio_context.dart b/packages/audioplayers_platform_interface/lib/src/api/audio_context.dart index d22907498..877151f5f 100644 --- a/packages/audioplayers_platform_interface/lib/src/api/audio_context.dart +++ b/packages/audioplayers_platform_interface/lib/src/api/audio_context.dart @@ -60,10 +60,11 @@ class AudioContextAndroid { final AndroidUsageType usageType; final AndroidAudioFocus audioFocus; + // Note when changing the defaults, it should also be changed in native code. const AudioContextAndroid({ - this.isSpeakerphoneOn = true, + this.isSpeakerphoneOn = false, this.audioMode = AndroidAudioMode.normal, - this.stayAwake = true, + this.stayAwake = false, this.contentType = AndroidContentType.music, this.usageType = AndroidUsageType.media, this.audioFocus = AndroidAudioFocus.gain, @@ -105,6 +106,7 @@ class AudioContextIOS { final AVAudioSessionCategory category; final List options; + // Note when changing the defaults, it should also be changed in native code. const AudioContextIOS({ this.category = AVAudioSessionCategory.playback, this.options = const [ diff --git a/packages/audioplayers_platform_interface/lib/src/api/audio_context_config.dart b/packages/audioplayers_platform_interface/lib/src/api/audio_context_config.dart index 0b4fcaa97..adaa498a7 100644 --- a/packages/audioplayers_platform_interface/lib/src/api/audio_context_config.dart +++ b/packages/audioplayers_platform_interface/lib/src/api/audio_context_config.dart @@ -74,7 +74,7 @@ class AudioContextConfig { final bool stayAwake; AudioContextConfig({ - this.forceSpeaker = true, + this.forceSpeaker = false, this.duckAudio = false, this.respectSilence = false, this.stayAwake = true, diff --git a/packages/audioplayers_platform_interface/test/global_platform_test.dart b/packages/audioplayers_platform_interface/test/global_platform_test.dart index 0eede3195..8b48b36b0 100644 --- a/packages/audioplayers_platform_interface/test/global_platform_test.dart +++ b/packages/audioplayers_platform_interface/test/global_platform_test.dart @@ -71,9 +71,9 @@ void main() { final call = popLastCall(); expect(call.method, 'setAudioContext'); expect(call.args, { - 'isSpeakerphoneOn': true, + 'isSpeakerphoneOn': false, 'audioMode': 0, - 'stayAwake': true, + 'stayAwake': false, 'contentType': 2, 'usageType': 1, 'audioFocus': 1, From c8c7ccf6449d8267315ec9aa3645e30991253084 Mon Sep 17 00:00:00 2001 From: Gustl22 Date: Tue, 4 Jul 2023 16:59:37 +0200 Subject: [PATCH 04/10] feat: remove AVAudioSessionOptions.mixWithOthers by default to match behavior of Android --- packages/audioplayers/test/global_audioplayers_test.dart | 4 +--- packages/audioplayers_darwin/ios/Classes/AudioContext.swift | 2 +- .../lib/src/api/audio_context.dart | 4 +--- .../lib/src/api/audio_context_config.dart | 5 +++-- .../test/global_platform_test.dart | 4 +--- 5 files changed, 7 insertions(+), 12 deletions(-) diff --git a/packages/audioplayers/test/global_audioplayers_test.dart b/packages/audioplayers/test/global_audioplayers_test.dart index 2395ea82d..8f763f3b0 100644 --- a/packages/audioplayers/test/global_audioplayers_test.dart +++ b/packages/audioplayers/test/global_audioplayers_test.dart @@ -49,9 +49,7 @@ void main() { ), iOS: AudioContextIOS( category: AVAudioSessionCategory.playback, - options: [ - AVAudioSessionOptions.mixWithOthers, - ], + options: [], ), ), ); diff --git a/packages/audioplayers_darwin/ios/Classes/AudioContext.swift b/packages/audioplayers_darwin/ios/Classes/AudioContext.swift index 3452ca2fe..9806b14c0 100644 --- a/packages/audioplayers_darwin/ios/Classes/AudioContext.swift +++ b/packages/audioplayers_darwin/ios/Classes/AudioContext.swift @@ -6,7 +6,7 @@ struct AudioContext { init() { self.category = .playback - self.options = [.mixWithOthers] + self.options = [] } init( diff --git a/packages/audioplayers_platform_interface/lib/src/api/audio_context.dart b/packages/audioplayers_platform_interface/lib/src/api/audio_context.dart index 877151f5f..1df4ab833 100644 --- a/packages/audioplayers_platform_interface/lib/src/api/audio_context.dart +++ b/packages/audioplayers_platform_interface/lib/src/api/audio_context.dart @@ -109,9 +109,7 @@ class AudioContextIOS { // Note when changing the defaults, it should also be changed in native code. const AudioContextIOS({ this.category = AVAudioSessionCategory.playback, - this.options = const [ - AVAudioSessionOptions.mixWithOthers, - ], + this.options = const [], }); AudioContextIOS copy({ diff --git a/packages/audioplayers_platform_interface/lib/src/api/audio_context_config.dart b/packages/audioplayers_platform_interface/lib/src/api/audio_context_config.dart index adaa498a7..9ce693554 100644 --- a/packages/audioplayers_platform_interface/lib/src/api/audio_context_config.dart +++ b/packages/audioplayers_platform_interface/lib/src/api/audio_context_config.dart @@ -124,8 +124,9 @@ class AudioContextConfig { : (forceSpeaker ? AVAudioSessionCategory.playAndRecord : AVAudioSessionCategory.playback), - options: [AVAudioSessionOptions.mixWithOthers] + - (duckAudio ? [AVAudioSessionOptions.duckOthers] : []) + + options: (duckAudio + ? [AVAudioSessionOptions.duckOthers] + : []) + (forceSpeaker ? [AVAudioSessionOptions.defaultToSpeaker] : []), ); } diff --git a/packages/audioplayers_platform_interface/test/global_platform_test.dart b/packages/audioplayers_platform_interface/test/global_platform_test.dart index 8b48b36b0..b5ce9d1aa 100644 --- a/packages/audioplayers_platform_interface/test/global_platform_test.dart +++ b/packages/audioplayers_platform_interface/test/global_platform_test.dart @@ -87,9 +87,7 @@ void main() { expect(call.method, 'setAudioContext'); expect(call.args, { 'category': 'playback', - 'options': [ - 'mixWithOthers', - ] + 'options': [] }); }); }); From bfb1b4ff7b4a30679a8ae796cdd1a3c654de87e2 Mon Sep 17 00:00:00 2001 From: Gustl22 Date: Tue, 4 Jul 2023 17:00:39 +0200 Subject: [PATCH 05/10] feat: make stayAwake by default false --- .../lib/src/api/audio_context_config.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/audioplayers_platform_interface/lib/src/api/audio_context_config.dart b/packages/audioplayers_platform_interface/lib/src/api/audio_context_config.dart index 9ce693554..37070ed6d 100644 --- a/packages/audioplayers_platform_interface/lib/src/api/audio_context_config.dart +++ b/packages/audioplayers_platform_interface/lib/src/api/audio_context_config.dart @@ -77,7 +77,7 @@ class AudioContextConfig { this.forceSpeaker = false, this.duckAudio = false, this.respectSilence = false, - this.stayAwake = true, + this.stayAwake = false, }); AudioContextConfig copy({ From e7850010997e0ad007a6a5ae9b3d7eb178228bee Mon Sep 17 00:00:00 2001 From: Gustl22 Date: Tue, 4 Jul 2023 17:37:05 +0200 Subject: [PATCH 06/10] feat: change forceSpeaker to AudioContextConfigRoute --- .../lib/src/api/audio_context_config.dart | 61 ++++++++++++------- 1 file changed, 40 insertions(+), 21 deletions(-) diff --git a/packages/audioplayers_platform_interface/lib/src/api/audio_context_config.dart b/packages/audioplayers_platform_interface/lib/src/api/audio_context_config.dart index 37070ed6d..4ce0ee853 100644 --- a/packages/audioplayers_platform_interface/lib/src/api/audio_context_config.dart +++ b/packages/audioplayers_platform_interface/lib/src/api/audio_context_config.dart @@ -16,18 +16,9 @@ import 'package:flutter/foundation.dart'; class AudioContextConfig { /// Normally, audio played will respect the devices configured preferences. /// However, if you want to bypass that and flag the system to use the - /// built-in speakers, you can set this flag. - /// - /// On android, it will set `audioManager.isSpeakerphoneOn`. - /// - /// On iOS, it will either: - /// - /// * set the `.defaultToSpeaker` option OR - /// * call `overrideOutputAudioPort(AVAudioSession.PortOverride.speaker)` - /// - /// Note that, on iOS, this forces the category to be `.playAndRecord`, and - /// thus is forbidden when [respectSilence] is set. - final bool forceSpeaker; + /// built-in speakers or the earpiece, you can set this flag. + /// See [AudioContextConfigRoute] for more details on the options. + final AudioContextConfigRoute route; /// This flag determines how your audio interacts with other audio playing on /// the device. @@ -74,20 +65,20 @@ class AudioContextConfig { final bool stayAwake; AudioContextConfig({ - this.forceSpeaker = false, + this.route = AudioContextConfigRoute.system, this.duckAudio = false, this.respectSilence = false, this.stayAwake = false, }); AudioContextConfig copy({ - bool? forceSpeaker, + AudioContextConfigRoute? route, bool? duckAudio, bool? respectSilence, bool? stayAwake, }) { return AudioContextConfig( - forceSpeaker: forceSpeaker ?? this.forceSpeaker, + route: route ?? this.route, duckAudio: duckAudio ?? this.duckAudio, respectSilence: respectSilence ?? this.respectSilence, stayAwake: stayAwake ?? this.stayAwake, @@ -103,11 +94,13 @@ class AudioContextConfig { AudioContextAndroid buildAndroid() { return AudioContextAndroid( - isSpeakerphoneOn: forceSpeaker, + isSpeakerphoneOn: route == AudioContextConfigRoute.speaker, stayAwake: stayAwake, usageType: respectSilence ? AndroidUsageType.notificationRingtone - : AndroidUsageType.media, + : (route == AudioContextConfigRoute.earpiece + ? AndroidUsageType.voiceCommunication + : AndroidUsageType.media), audioFocus: duckAudio ? AndroidAudioFocus.gainTransientMayDuck : AndroidAudioFocus.gain, @@ -121,22 +114,48 @@ class AudioContextConfig { return AudioContextIOS( category: respectSilence ? AVAudioSessionCategory.ambient - : (forceSpeaker + : (route == AudioContextConfigRoute.speaker ? AVAudioSessionCategory.playAndRecord - : AVAudioSessionCategory.playback), + : (route == AudioContextConfigRoute.earpiece + ? AVAudioSessionCategory.playAndRecord + : AVAudioSessionCategory.playback)), options: (duckAudio ? [AVAudioSessionOptions.duckOthers] : []) + - (forceSpeaker ? [AVAudioSessionOptions.defaultToSpeaker] : []), + (route == AudioContextConfigRoute.speaker + ? [AVAudioSessionOptions.defaultToSpeaker] + : []), ); } void validateIOS() { // Please create a custom [AudioContextIOS] if the generic flags cannot // represent your needs. - if (respectSilence && forceSpeaker) { + if (respectSilence && route == AudioContextConfigRoute.speaker) { throw 'On iOS it is impossible to set both respectSilence and ' 'forceSpeaker'; } } } + +enum AudioContextConfigRoute { + /// Use the system's default route. This can be e.g. the built-in speaker, the + /// earpiece, or a bluetooth device. + system, + + /// On android, it will set `AndroidUsageType.voiceCommunication`. + /// + /// On iOS, it will set `AVAudioSessionCategory.playAndRecord`. + earpiece, + + /// On android, it will set `audioManager.isSpeakerphoneOn`. + /// + /// On iOS, it will either: + /// + /// * set the `.defaultToSpeaker` option OR + /// * call `overrideOutputAudioPort(AVAudioSession.PortOverride.speaker)` + /// + /// Note that, on iOS, this forces the category to be `.playAndRecord`, and + /// thus is forbidden when [respectSilence] is set. + speaker, +} From bb74deef6f7a0b8d0014fada868aaecaab3c9907 Mon Sep 17 00:00:00 2001 From: Gustl22 Date: Tue, 4 Jul 2023 17:43:36 +0200 Subject: [PATCH 07/10] test: change example and tests --- .../example/integration_test/lib_test.dart | 8 ++++---- .../example/lib/tabs/audio_context.dart | 13 ++++++++----- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/packages/audioplayers/example/integration_test/lib_test.dart b/packages/audioplayers/example/integration_test/lib_test.dart index 3a658bd49..5c7aff6a6 100644 --- a/packages/audioplayers/example/integration_test/lib_test.dart +++ b/packages/audioplayers/example/integration_test/lib_test.dart @@ -153,7 +153,7 @@ void main() { var audioContext = AudioContextConfig( //ignore: avoid_redundant_argument_values - forceSpeaker: true, + route: AudioContextConfigRoute.system, //ignore: avoid_redundant_argument_values respectSilence: false, ).build(); @@ -170,7 +170,7 @@ void main() { expect(player.state, PlayerState.completed); audioContext = AudioContextConfig( - forceSpeaker: false, + route: AudioContextConfigRoute.speaker, respectSilence: true, ).build(); await AudioPlayer.global.setAudioContext(audioContext); @@ -203,7 +203,7 @@ void main() { var audioContext = AudioContextConfig( //ignore: avoid_redundant_argument_values - forceSpeaker: true, + route: AudioContextConfigRoute.system, //ignore: avoid_redundant_argument_values respectSilence: false, ).build(); @@ -223,7 +223,7 @@ void main() { expect(player.state, PlayerState.stopped); audioContext = AudioContextConfig( - forceSpeaker: false, + route: AudioContextConfigRoute.speaker, respectSilence: true, ).build(); await AudioPlayer.global.setAudioContext(audioContext); diff --git a/packages/audioplayers/example/lib/tabs/audio_context.dart b/packages/audioplayers/example/lib/tabs/audio_context.dart index e3c573ac8..e3bc73ed3 100644 --- a/packages/audioplayers/example/lib/tabs/audio_context.dart +++ b/packages/audioplayers/example/lib/tabs/audio_context.dart @@ -103,11 +103,14 @@ class AudioContextTabState extends State Widget _genericTab() { return TabContent( children: [ - Cbx( - 'Force Speaker', - value: audioContextConfig.forceSpeaker, - ({value}) => - updateConfig(audioContextConfig.copy(forceSpeaker: value)), + LabeledDropDown( + label: 'Audio Route', + key: const Key('audioRoute'), + options: {for (var e in AudioContextConfigRoute.values) e: e.name}, + selected: audioContextConfig.route, + onChange: (v) => updateConfig( + audioContextConfig.copy(route: v), + ), ), Cbx( 'Duck Audio', From 7bf952b41814427a50af82ad458f94a39325bfca Mon Sep 17 00:00:00 2001 From: Gustl22 Date: Tue, 4 Jul 2023 18:42:29 +0200 Subject: [PATCH 08/10] dart format . --- .../test/global_platform_test.dart | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/audioplayers_platform_interface/test/global_platform_test.dart b/packages/audioplayers_platform_interface/test/global_platform_test.dart index b5ce9d1aa..3477d2468 100644 --- a/packages/audioplayers_platform_interface/test/global_platform_test.dart +++ b/packages/audioplayers_platform_interface/test/global_platform_test.dart @@ -85,10 +85,7 @@ void main() { await platform.setGlobalAudioContext(const AudioContext()); final call = popLastCall(); expect(call.method, 'setAudioContext'); - expect(call.args, { - 'category': 'playback', - 'options': [] - }); + expect(call.args, {'category': 'playback', 'options': []}); }); }); From 16cd699e5c05ff9d9282aac11276725aa6347091 Mon Sep 17 00:00:00 2001 From: Gustl22 Date: Tue, 4 Jul 2023 18:46:22 +0200 Subject: [PATCH 09/10] fix route on ios tests --- .../audioplayers/example/integration_test/lib_test.dart | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/audioplayers/example/integration_test/lib_test.dart b/packages/audioplayers/example/integration_test/lib_test.dart index 5c7aff6a6..0a06a794e 100644 --- a/packages/audioplayers/example/integration_test/lib_test.dart +++ b/packages/audioplayers/example/integration_test/lib_test.dart @@ -170,7 +170,8 @@ void main() { expect(player.state, PlayerState.completed); audioContext = AudioContextConfig( - route: AudioContextConfigRoute.speaker, + //ignore: avoid_redundant_argument_values + route: AudioContextConfigRoute.system, respectSilence: true, ).build(); await AudioPlayer.global.setAudioContext(audioContext); @@ -223,7 +224,8 @@ void main() { expect(player.state, PlayerState.stopped); audioContext = AudioContextConfig( - route: AudioContextConfigRoute.speaker, + //ignore: avoid_redundant_argument_values + route: AudioContextConfigRoute.system, respectSilence: true, ).build(); await AudioPlayer.global.setAudioContext(audioContext); From 0caf4d234550829216dff34d2c7f95d5834d24ec Mon Sep 17 00:00:00 2001 From: Gustl22 Date: Tue, 4 Jul 2023 23:11:04 +0200 Subject: [PATCH 10/10] fix analyze --- .../lib/src/api/audio_context_config.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/audioplayers_platform_interface/lib/src/api/audio_context_config.dart b/packages/audioplayers_platform_interface/lib/src/api/audio_context_config.dart index 4ce0ee853..9f1c58266 100644 --- a/packages/audioplayers_platform_interface/lib/src/api/audio_context_config.dart +++ b/packages/audioplayers_platform_interface/lib/src/api/audio_context_config.dart @@ -156,6 +156,6 @@ enum AudioContextConfigRoute { /// * call `overrideOutputAudioPort(AVAudioSession.PortOverride.speaker)` /// /// Note that, on iOS, this forces the category to be `.playAndRecord`, and - /// thus is forbidden when [respectSilence] is set. + /// thus is forbidden when [AudioContextConfig.respectSilence] is set. speaker, }