【问题标题】:Type of expression is ambiguous without more context AVAudioSession表达式类型不明确,没有更多上下文 AVAudioSession
【发布时间】:2019-04-23 20:26:40
【问题描述】:

我正在尝试添加通知观察器以检测何时移除耳机并且音乐停止播放。我关注了Audio Session。我正在尝试搜索 Swift 4.2 语法,从 Apple 的原始代码中更改了一些内容,但我仍然收到此错误:

没有更多上下文的表达类型是模棱两可的

我做错了什么?如果我需要添加更多代码,请告诉我

override func awakeFromNib() {
    super.awakeFromNib()

    NotificationCenter.default.addObserver(self, selector: #selector(audioRouteChanged), name: .AVAudioSession.routeChangeNotification, object: nil)
    //Error this line: Type of expression is ambiguous without more context

}

@objc func audioRouteChanged(notification: Notification) {

    guard let userInfo = notification.userInfo else { return }
    guard let reason = userInfo[AVAudioSessionRouteChangeReasonKey] as? Int else { return }

    if reason == AVAudioSession.RouteChangeReason.oldDeviceUnavailable.hashValue {
        // headphones plugged out
        // continue playback or change the play/pause icon
        playPauseButton.setImage(#imageLiteral(resourceName: "play"), for: .normal)
        miniPlayPauseButton.setImage(#imageLiteral(resourceName: "play"), for: .normal)
    }
}

【问题讨论】:

  • 您在.AVAudioSession.routeChangeNotification 中有一个领先的.。删除将解决错误。
  • 是的,我修好了,非常感谢

标签: swift avaudiosession


【解决方案1】:

去掉AVAudioSession前面的点name: .AVAudioSession.routeChangeNotification

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-30
    • 2019-02-01
    • 2019-04-22
    • 1970-01-01
    相关资源
    最近更新 更多