Ios 在不中断背景媒体播放的情况下录制音频

Ios 在不中断背景媒体播放的情况下录制音频,ios,swift,iphone,Ios,Swift,Iphone,是否可以在不中断背景媒体播放(如音乐)的情况下在iOS上录制音频 如果可能,应使用哪种音频会话类别和模式,以及音频录像机设置 我目前使用的代码是: do { try session.setCategory(.record, options: [.mixWithOthers]) try session.setActive(true) let settings = [ AVFormatIDKey: Int(kAudioFormatMPEG4AAC),

是否可以在不中断背景媒体播放(如音乐)的情况下在iOS上录制音频

如果可能,应使用哪种音频会话类别和模式,以及音频录像机设置

我目前使用的代码是:

do {
    try session.setCategory(.record, options: [.mixWithOthers])
    try session.setActive(true)
    let settings = [
        AVFormatIDKey: Int(kAudioFormatMPEG4AAC),
        AVSampleRateKey: 44100,
        AVNumberOfChannelsKey: 2,
        AVEncoderAudioQualityKey: AVAudioQuality.high.rawValue
    ]
    audioRecorder = try AVAudioRecorder(url: genPath(), settings: settings)
} catch let error {
    alert(title: "Error", message: error.localizedDescription)
    return false
}

会话类别更改为。播放和录制

session.setCategory(.playAndRecord, options: [.mixWithOthers, .allowAirPlay, .allowBluetoothA2DP])


请参见-

会话类别更改为。播放和录制

session.setCategory(.playAndRecord, options: [.mixWithOthers, .allowAirPlay, .allowBluetoothA2DP])


请参阅-

更新的问题。这与在后台开始录制无关。更改为
session.setCategory(.play和Record,选项:[.mixWithOthers、.allowAirPlay、.allowBluetoothA2DP])
解决更新的问题。这与在后台开始录制无关。更改为
session.setCategory(.play和Record,选项:[.mixWithOthers、.allowAirPlay、.allowBluetoothA2DP])
解决此问题