jpsim / JPSVolumeButtonHandler

JPSVolumeButtonHandler provides an easy block interface to hardware volume buttons on iOS devices. Perfect for camera apps!
MIT License
333 stars 90 forks source link

First use permanently dampens some system sounds until app restart #37

Open jmbremer opened 7 years ago

jmbremer commented 7 years ago

First of all: Thanks a lot for offering and maintaining this very helpful piece of code!

In short: When first creating (and using) an instance of this handler, the handler somehow mutes some system sounds to some degree, e.g., AudioServicesPlaySystemSound(1104). Disabling and releasing the handler does not undo this effect. Only restarting the app resets volume levels to normal. The effect may be slight enough for anyone, who is not heavily relying on other system sounds, to miss it.

Details: I have UIButtons that indicate a press by playing a system sound. At medium volume levels, this sound is quite clearly audible. As soon as a I enable support of volume button taps through this module (as an alternative means to tap those UIButtons, a means that can be switched on and off dynamically), the same sounds are still played, but at significantly reduced volume. The volume also remains at this constant low level when disabling the button handler entirely again.

Furthermore, before creating the first instance of this module, system sounds react to changes in volume (not in a major way, but clearly audible). Once I create a first instance of the handler, volume levels for the system sounds affected remain constant(ly low) no matter the volume level.

Finally, weirdly enough, this unpleasant effect only seems to concern some system sounds (like 1104) but not others (like 1103). There is not a whole lot of fancy in my code and in particular the treatment of different system sounds. So, it seems rather unlikely that the effects described are caused in my code.

I am a fairly long-time user of this module. I notice the effects more pronounced now, because of a more systematic use of system sounds. However, I do believe that I noticed the same effects a year ago already. So, it does seem to me that the volume button handler code does some permanent damage to the system's volume handling for some time.

(I notice another effect where, right after switching the handler on for the first time, the first system sounds that follow are completely dropped or cause a significant delay in app execution up to approximately several 100s of milliseconds. But this effect is even more erratic, so I cannot pinpoint it perfectly yet.)

Any ideas how to fix this? -- And notice that, if you are using this module (a) as always switched on like in a typical camera app or (b) in an app without any significant sound, it will be hard to notice. In my case, it's rather noticeable and confusing to users. Thanks for any reaction!

EDIT: I could add that this is how I play those system sounds: GlobalUserInitiatedQueue.async { AudioServicesPlaySystemSound(soundId) return } where var GlobalUserInitiatedQueue: DispatchQueue { return DispatchQueue.global(qos: .userInitiated) }