native-audio
native-audio copied to clipboard
On iOS make the AVAudioSession.Category configurable to support the silent switch
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
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?
Yes, I'm using NativeAudio.preloadComplex
and find that it doesn't mute the sound when using toggling the switch off.
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.
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
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?
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
Any news on this? Still struggling to find a solution.