andreamazz / SubtleVolume

Replace the system volume popup with a more subtle indicator.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Crash when trying to manual setVolumeLevel without animated

tienphong923 opened this issue · comments

Hi, I was tried to manual setVolumeLevel without animated = false but app crashed.

*** Terminating app due to uncaught exception 'NSRangeException', reason: 'Cannot remove an observer <SubtleVolume.SubtleVolume 0x11bc79d80> for the key path "outputVolume" from <AVAudioSession 0x11bc389f0> because it is not registered as an observer.'

Hey @tienphong923
I can't reproduce that crash, but there was an issue with the setVolumeLevel without animation (fixed now).

The observer is removed only on deinit, so that's weird. Can you post some of your code?

Hi @andreamazz

Sorry, that's my fail. My project used UISlider to adjust volume. When slider's value changed, it attempted to setVolumeLevel continuous.

With animated is false, I found your setVolumeLevel function remove observer and re-add observer after 0.1 second later. When I setVolumeLevel continuous, observer hasn't added (maybe below 0.1 second) so it crashed!

So my problem resolved by prevent setVolumeLevel continuous.

With your Demo (on version 0.5.1), when I was setVolumeLevel with animated=false, maybe progressbar not changed when I touched on increase button (+). And touch many times and quickly, it crashed with the same issue (Cannot remove an observer).

Great project, thanks for all!