【问题标题】:Swift: how to set up an audio session that gracefully mixes with others (aka Pod)Swift:如何设置与其他人优雅混合的音频会话(又名 Pod)
【发布时间】:2014-10-30 14:15:43
【问题描述】:

这段代码 sn-p 使其他音频(又名 iPod)停止:

func setSessionPlayer() {

    var audioSessionError: NSError?
    let audioSession = AVAudioSession.sharedInstance()

    audioSession.setActive(true, error: nil)

    if audioSession.setCategory(AVAudioSessionCategoryPlayback, withOptions:AVAudioSessionCategoryOptions.MixWithOthers,
        error: &audioSessionError) {
            println("Successfully set the audio session")
    } else {
        println("Could not set the audio session")
    }

}

我错过了什么?

【问题讨论】:

    标签: audio swift ios8.1


    【解决方案1】:

    我认为这是因为您在将 audioSession.active 配置为 MixWithOthers 之前对其进行了设置。将audioSession.setActive 移动到 if 块下方,如下所示:

    if audioSession.setCategory(AVAudioSessionCategoryPlayback, withOptions:AVAudioSessionCategoryOptions.MixWithOthers,
        error: &audioSessionError) {
            println("Successfully set the audio session")
    } else {
        println("Could not set the audio session")
    }
    
    audioSession.setActive(true, error: nil)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-10-20
      • 2016-04-06
      • 2010-10-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多