是否可以在不中断背景媒体播放(例如音乐)的情况下在iOS上录制音频?
如果可能的话,应使用哪种AVAudioSession类别和模式,以及AVAudioRecorder设置?
我现在无法使用的代码是:
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
}
答案 0 :(得分:2)
将 sessionCategory 更改为 .playAndRecord :
session.setCategory(.playAndRecord, options: [.mixWithOthers, .allowAirPlay, .allowBluetoothA2DP])
推荐者-link