使用下面的代码,我得到了输出音量,但它确实不一致-有时它给出了相同的值,有时它是一个音量变化背后,尽管系统音量实际上正确地改变。
有没有办法让它每次都输出正确的值?
func viewDidLoad() {
...
NotificationCenter.default.addObserver(self, selector: #selector(volumeDidChange), name: NSNotification.Name(rawValue: "AVSystemController_SystemVolumeDidChangeNotification"), object: nil)
...
}
func volumeDidChange() {
print("VOLUME CHANGING", AVAudioSession.sharedInstance().outputVolume)
// output while changing the volume with hardware buttons
VOLUME CHANGING 0.0625
VOLUME CHANGING 0.0625
VOLUME CHANGING 0.125
VOLUME CHANGING 0.1875
VOLUME CHANGING 0.25
VOLUME CHANGING 0.375
VOLUME CHANGING 0.375
VOLUME CHANGING 0.4375
VOLUME CHANGING 0.5
VOLUME CHANGING 0.5625
VOLUME CHANGING 0.625
VOLUME CHANGING 0.6875
VOLUME CHANGING 0.75
VOLUME CHANGING 0.8125
VOLUME CHANGING 0.875
VOLUME CHANGING 0.75
VOLUME CHANGING 0.6875
VOLUME CHANGING 0.625
VOLUME CHANGING 0.625
VOLUME CHANGING 0.5625
VOLUME CHANGING 0.5
VOLUME CHANGING 0.4375
VOLUME CHANGING 0.375
VOLUME CHANGING 0.3125
VOLUME CHANGING 0.375
VOLUME CHANGING 0.4375
VOLUME CHANGING 0.4375
2条答案
按热度按时间uyto3xhc1#
尝试
您当前的输出-重复相同的值
所需输出
quhf5bfb2#
Swift 4.2更新