Ios Swift:共享扩展中的音频录制仅在第一次运行时有效
我正在使用AVAudioRecorder录制共享分机中的音频。它在第一次运行时运行良好,但从那里我无法录制另一个音频Ios Swift:共享扩展中的音频录制仅在第一次运行时有效,ios,swift,audio,avaudioplayer,swift-extensions,Ios,Swift,Audio,Avaudioplayer,Swift Extensions,我正在使用AVAudioRecorder录制共享分机中的音频。它在第一次运行时运行良好,但从那里我无法录制另一个音频 var audioRecorder : AVAudioRecorder? 加载 let dirPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true) let docDir = dirPath[0] let sou
var audioRecorder : AVAudioRecorder?
加载
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()