我试图快速制作一个录音机,但遇到了这个问题。如果我创建两个同名的声音文件,第一个文件会被第二个文件替换,还是第一个文件仍然存在但我找不到它?
这是我的代码:
func setup_recorder强文本(){
var recordSettings = [
AVFormatIDKey: kAudioFormatAppleLossless,
AVEncoderAudioQualityKey : AVAudioQuality.Max.rawValue,
AVEncoderBitRateKey : 320000,
AVNumberOfChannelsKey: 2,
AVSampleRateKey : 44100.0
]
time_display_1 = 0
timer_1 = NSTimer.scheduledTimerWithTimeInterval(0.01, target: self, selector: "timer_update_1", userInfo: nil, repeats: true)
var dir_path = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)
var doc_dir: AnyObject = dir_path[0]
var sound_file_path = doc_dir.stringByAppendingPathComponent("1.m4a")
sound_file_URL_1 = NSURL(fileURLWithPath: sound_file_path)
let file_manager = NSFileManager.defaultManager()
if file_manager.fileExistsAtPath(sound_file_path) {
println("sound exists")
}
var error: NSError?
recorder_1 = AVAudioRecorder(URL: sound_file_URL_1!, settings: recordSettings, error: &error)
if let e = error {
println(e.localizedDescription)
}
else {
recorder_1.meteringEnabled = true
recorder_1.prepareToRecord()
}
}
最佳答案
if i create two sound file with the same name, does the first file get replaced by the second
是,AVAudioRecorder
将用新数据覆盖(即替换)现有文件。为避免这种情况,请先检查该文件是否存在,如果存在则选择一个不同的名称。
关于swift - 在 swift 。当我创建两个同名的声音文件时,第二个是否会替换第一个?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29151057/