【问题标题】:in swift. when i create two sound files with the name, does the second on replace the first one?迅速。当我创建两个同名的声音文件时,第二个会替换第一个吗?
【发布时间】:2015-05-22 22:46:39
【问题描述】:

我正在尝试快速制作录音机,但遇到了这个问题。如果我创建了两个同名的声音文件,是第一个文件被第二个文件替换还是第一个文件仍然存在但我找不到它?

这是我的代码:

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()
    }
}

【问题讨论】:

    标签: swift nsurl avaudiorecorder


    【解决方案1】:

    如果我创建了两个同名的声音文件,第一个文件是否会被第二个文件替换

    AVAudioRecorder 将用新数据覆盖(即替换)现有文件。为避免这种情况,请先检查文件是否存在,如果存在则选择其他名称。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-19
      • 2021-03-10
      • 1970-01-01
      相关资源
      最近更新 更多