我正在运行iPad iOS 9.3.4 (本文撰写时的最新版本)。
我正在运行以下代码:
let settings = [
AVFormatIDKey: NSNumber(unsignedInt: kAudioFormatMPEG4AAC),
AVSampleRateKey: 44100.0,
AVNumberOfChannelsKey: 2 as NSNumber,
AVEncoderAudioQualityKey: AVAudioQuality.High.rawValue
]
do {
audioRecorder = try AVAudioRecorder(URL: audioURL, settings: settings)
audioRecorder.delegate = self
audioRecorder.record()
} catch let error as NSError{
print(error.description)
}
我发现了这个错误:
错误Domain=NSOSStatusErrorDomain Code=1718449215 "(null)“
当我尝试使用目标-C- AVAudioRecorder时,我能够毫无问题地记录下来。这个问题似乎只发生在Swift上,而且只出现在设备上--在模拟器中没有问题。
如果我用kAudioFormatMPEG4AAC与kAudioFormatLinearPCM切换,我就能录制--但当我试图播放任何播放的录音--它似乎没有很好的录制。
最近有没有人能用AVAudioRecorder在Swift上录制,并且把录音放回真实的iPad上?我只想要那个密码。
发布于 2019-07-30 11:23:52
输出文件路径扩展名必须与AVFormatIDKey同步
对于.wav
let recordSettings:[String:Any] = [AVFormatIDKey:kAudioFormatLinearPCM,
AVEncoderAudioQualityKey:AVAudioQuality.max.rawValue,
AVEncoderBitRateKey:320000,
AVNumberOfChannelsKey:2,
AVSampleRateKey:44100.0 ] as [String : Any]
对于.m4a
let recordSettings:[String:Any] = [AVFormatIDKey:kAudioFormatAppleLossless,
AVEncoderAudioQualityKey:AVAudioQuality.max.rawValue,
AVEncoderBitRateKey:320000,
AVNumberOfChannelsKey:2,
AVSampleRateKey:44100.0 ] as [String : Any]
发布于 2016-08-16 13:00:00
看来我从来没有把录音会话设置为活动的。不过,我希望错误描述更好。
override init() {
super.init()
recordingSession = AVAudioSession.sharedInstance()
do {
try recordingSession.setCategory(AVAudioSessionCategoryPlayAndRecord)
try recordingSession.setActive(true)
recordingSession.requestRecordPermission() { (allowed: Bool) -> Void in
dispatch_async(dispatch_get_main_queue()) {
if allowed {
// success
} else {
// TBD: Show a message to the user that they need to give permission in settings app to proceed
}
}
}
} catch {
// TBD: Show a message to the user that they need to give permission in settings app to proceed
}
}
https://stackoverflow.com/questions/38969331
复制相似问题