andreamazz / SubtleVolume

Replace the system volume popup with a more subtle indicator.
MIT License
1.2k stars 63 forks source link

Crash when trying to manual setVolumeLevel without animated #15

Open tienphong923 opened 6 years ago

tienphong923 commented 6 years ago

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.'

andreamazz commented 6 years ago

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?

tienphong923 commented 6 years ago

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!