2

此代码片段使其他音频(又名 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")
    }

}

我错过了什么?

4

1 回答 1

3

我认为这是因为您在将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)
于 2014-10-30T14:43:51.730 回答