【问题标题】:Other audio being ducked even when device is silenced and category is ambient即使设备已静音且类别为环境,其他音频也会被闪避
【发布时间】:2021-10-20 15:12:35
【问题描述】:

我希望我的应用程序中的音频能够避开在后台播放的音乐,但也不会在铃声/静音开关切换到静音模式时播放。我可以通过以下AVAudioSession 配置获得这种行为,但需要注意的是——当正在播放音乐并且设备静音时,它仍然在闪避音乐,即使我的应用程序(正确)实际上并没有播放任何音频。

是否有配置可以使其正常工作?当应用程序实际上不播放音频时,系统会躲避其他人,这似乎很奇怪。这可能是iOS中的错误吗?

try AVAudioSession.sharedInstance().setCategory(.ambient, mode: .default, options: [.duckOthers, .interruptSpokenAudioAndMixWithOthers])

【问题讨论】:

    标签: ios avaudiosession avaudiosessioncategory


    【解决方案1】:

    这是我已经实现的,我只是将我的 iPad 静音,它没有声音。但我不确定 iPhone 上的行为是否相同,因为我通常总是将手机静音并仍然听到音频...

      do {
        try AVAudioSession.sharedInstance().setCategory(.playback, options: .duckOthers)
      } catch(let error) {
        print(error.localizedDescription)
      }
      
      let utterance = AVSpeechUtterance(string: stringToSpeak)
      
      // Set voice to male or female based on user settings
      if defaults.integer(forKey: "Voice") == 1 {
        utterance.voice = AVSpeechSynthesisVoice(identifier: "com.apple.ttsbundle.siri_male_ja-JP_compact")
      }
      
      else {
        utterance.voice = AVSpeechSynthesisVoice(language: "ja-JP")
      }
      
      synthesizer.speak(utterance)
    

    【讨论】:

    • 不幸的是,“播放”类别使其不尊重铃声开关。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-30
    • 2012-07-24
    相关资源
    最近更新 更多