Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
djadu opened this issue Feb 22, 2021 · 7 comments

Comments

@djadu
Copy link

djadu commented Feb 22, 2021

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

@dsl101
Copy link

dsl101 commented Mar 7, 2021

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?

@djadu
Copy link
Author

djadu commented Mar 8, 2021

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

@dsl101
Copy link

dsl101 commented Mar 8, 2021

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.

@djadu
Copy link
Author

djadu commented Mar 8, 2021

Interesting, looking at the following line, the app should actually always play the audio based on the category of Playback

try session.setCategory(AVAudioSession.Category.playback)

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

@dsl101
Copy link

dsl101 commented Mar 8, 2021

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?

@riderx
Copy link
Contributor

riderx commented Dec 3, 2021

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

@f-bog
Copy link

f-bog commented Apr 6, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants