[英]Not able to set category for AVAudioSession
尝试使用AVAudioSession
录制音频。 但是不能设置类别最终会导致模棱两可而没有上下文错误。
我正在使用Swift 4。
@objc func setupRecorder() {
recordingSession = AVAudioSession.sharedInstance()
do {
try recordingSession?.setCategory(.playAndRecord, mode: .default)
try recordingSession.setActive(true)
recordingSession.requestRecordPermission() { [unowned self] allowed in
DispatchQueue.main.async {
if allowed {
self.startRecording()
} else {
// failed to record!
}
}
}
} catch {
// failed to record!
}
}
如果使用“ Swift4”,则设置类别的方法不同,即
AVAudioSession.sharedInstance().setCategory(String, mode: String, options: AVAudioSessionCategoryOptions)
广告,您可以通过以下方式使用它:
try? AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayAndRecord, mode: AVAudioSessionModeDefault, options: AVAudioSessionPortBuiltInSpeaker)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.