native-audio icon indicating copy to clipboard operation
native-audio copied to clipboard

On iOS make the AVAudioSession.Category configurable to support the silent switch

Open djadu opened this issue 4 years ago • 7 comments

Is your feature request related to a problem? Please describe. When playing audio with iOS, users expect for apps to silence the audio when the physical silent switch is toggled off.

This is supported in the API by setting the appropriate category on AVAudioSession.sharedInstance().setCategory which is hardcoded to "playback" in the plugin.

Describe the solution you'd like Add a configuration parameter for iOS, perhaps in preloadComplex to set the iOS Audio Session category

Describe alternatives you've considered Remove AVAudioSession.sharedInstance().setCategory from the plugin and let each app set it's own category in AppDelegate.

Additional context See documentation here: https://developer.apple.com/documentation/avfaudio/avaudiosessioncategory

djadu avatar Feb 22 '21 11:02 djadu

Actually, I'm after the opposite—I find on ios that the mute switch does silence NativeAudio.play(), but I'd like to be able to play alert sounds regardless of the switch position. Are you seeing that differently?

dsl101 avatar Mar 07 '21 20:03 dsl101

Yes, I'm using NativeAudio.preloadComplex and find that it doesn't mute the sound when using toggling the switch off.

djadu avatar Mar 08 '21 15:03 djadu

Interesting—I've tried simple and complex, and find the toggle affects both :). I'm using a .m4a file and this is on an iphone 8 with ios 14.4.

dsl101 avatar Mar 08 '21 15:03 dsl101

Interesting, looking at the following line, the app should actually always play the audio based on the category of Playback https://github.com/capacitor-community/native-audio/blob/57b9a8e4f4f3f3449f8e5ad0df9f2b29fb760405/ios/Plugin/Plugin.swift#L27

See Apple docs: https://developer.apple.com/documentation/avfaudio/avaudiosessioncategoryplayback

djadu avatar Mar 08 '21 15:03 djadu

I just tried my app in the iPhone simulator for iPhone 8, and it behaves exactly as you suggest. But on my physical iPhone 8, the silent toggle silences the sounds. I wonder if there is a phone setting involved somewhere as well?

dsl101 avatar Mar 08 '21 16:03 dsl101

I made a plugin to allow to detect mute in ios/android and let show to user he will have no sound in mute: https://github.com/riderx/capacitor-mute

riderx avatar Dec 03 '21 16:12 riderx

Any news on this? Still struggling to find a solution.

f-bog avatar Apr 06 '22 05:04 f-bog