微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

应用因更改音量而崩溃,状态为收到KVO消息,但未针对键路径“ outputVolume”进行处理

如何解决应用因更改音量而崩溃,状态为收到KVO消息,但未针对键路径“ outputVolume”进行处理

每次更改音量时,我的应用都会崩溃。它告诉我我没有处理来自AVAudioSession的通知,但是我已经为此设置了观察者并设置了一个断点以确保确实得到处理。

    var kvoVolumeObs: NSkeyvalueObservation?

    func observe() {
    kvoVolumeObs = audioSession.observe(\.outputVolume,options: [.new,.old],changeHandler: { (session,change) in
         print("volume for session \(session.outputVolume)")
        if let player = self.player {
            player.setVolume(session.outputVolume)
        }
    })
}

也许我没有在正确的地方处理它?

我在AVPlayer类中将AVAudioSession设置为活动状态,但是我不希望它发起KVO调用

    func startAudioSession() {
    backgroundSessionKillTimer?.invalidate()
    dispatchQueue.global().async {
        do {
            try AVAudioSession.sharedInstance().setActive(true,options: AVAudioSession.SetActiveOptions.notifyOthersOnDeactivation)
        } catch let error as NSError {
            print("Failed to set AudioSession Stuff \(error.localizedDescription)")
        }
    }
}

我一直在解决这个问题有一段时间。任何帮助将不胜感激。

下面是崩溃的调试语句。

2020-09-28 08:00:11.082153-0600 98.5 KYGO[1507:259676] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException',reason: '<CFRunLoopSource 0x1044d1840 [0x1e13d5b40]>{signalled = No,valid = Yes,order = 0,context = <SCNetworkReachability RLS> {target = 0x10bcf8f80}}: An -observeValueForKeyPath:ofObject:change:context: message was received but not handled.
Key path: outputVolume
Observed object: <AVAudioSession: 0x10444d5a0>
Change: {
    kind = 1;
    new = 1;
}
Context: 0x0'
*** First throw call stack:
(0x193951114 0x1a7177cb4 0x194bc8f84 0x194bc90a4 0x194bcb4d8 0x194bc88d0 0x19adc869c 0x19adc1404 0x102b97db8 0x102b995fc 0x102ba7a6c 0x1938d0c30 0x1938cb0e8 0x1938ca200 0x1a99c5598 0x196190004 0x1961955d8 0x100fe9248 0x1935a9598)
libc++abi.dylib: terminating with uncaught exception of type NSException
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException',context = <SCNetworkReachability RLS> {target = 0x10bcf8f80}}: An -observeValueForKeyPath:ofObject:change:context: message was received but not handled.
Key path: outputVolume
Observed object: <AVAudioSession: 0x10444d5a0>
Change: {
    kind = 1;
    new = 1;
}
Context: 0x0'
terminating with uncaught exception of type NSException

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。