如何解决Swift:共享扩展中的音频记录仅在首次运行时起作用
我正在使用AVAudioRecorder进行录制以在共享扩展名中录制音频。首次运行时效果很好,但是从那里我无法录制其他音频。
var audioRecorder : AVAudioRecorder?
在viewdidload上
let dirPath = NSSearchPathForDirectoriesInDomains(.documentDirectory,.userDomainMask,true)
let docDir = dirPath[0]
let soundFilePath = (docDir as NSString).appendingPathComponent("sound.wav")
soundFileURL = NSURL(fileURLWithPath: soundFilePath) as URL
print(soundFilePath)
//Setting for recorder
let recordSettings = [AVEncoderAudioQualityKey: AVAudioQuality.max.rawValue,AVEncoderBitRateKey: 16,AVNumberOfChannelsKey : 2,AVSampleRateKey: 44100.0] as [String : Any] as [String : Any] as [String : Any] as [String : Any]
var error : NSError?
let audioSession = AVAudioSession.sharedInstance()
do {
try audioSession.setCategory(AVAudioSessionCategoryPlayAndRecord)
self.audioRecorder = try AVAudioRecorder(url: soundFileURL!,settings: recordSettings as [String : AnyObject])
} catch _ {
print("Error")
}
if let err = error {
print("audioSession error: \(err.localizedDescription)")
}else{
self.audioRecorder?.prepareToRecord()
}
在记录按钮上单击
self.audioRecorder?.record()
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。