简体   繁体   中英

Detect Volume button press EVEN when volume is max

I want to detect when the volume button is pressed. I've try a lot of thing like add an Observer like

AVAudioSession.sharedInstance().addObserver(self, forKeyPath: #keyPath(AVAudioSession.outputVolume), options: [.old, .new], context: nil)

then Override :

override internal func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey: Any]?, context: UnsafeMutableRawPointer?)

But I want to trigger this function even if the sound is at max.

There is a way to do that without changing so sound to lower it ?

Try

  AVAudioSession.sharedInstance().setActive(true)
  AVAudioSession.sharedInstance().observe(\.outputVolume) { [weak self] (audioSession, _) in
        <#code#>
    }

See https://github.com/andreamazz/SubtleVolume

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM