iOS -Record .m4a文件,查看并从iTunes / mac检索

时间:2019-02-25 13:34:29

标签: ios swift avfoundation audio-recording

所以我正在按照以下方式记录文件,但是我试图从Mac中检索文件:

var fileName: String = "audioFile.m4a"

func getDocDirector() -> URL {
    let path = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
    return path[0]
}

func setUpRecorder() {
    let audioFileName = getDocDirector().appendingPathComponent(fileName)
    print("file name:\(audioFileName)")

    let recordSettings: [String: Any] = [AVFormatIDKey: Int(kAudioFormatMPEG4AAC),
                                         AVEncoderAudioQualityKey: AVAudioQuality.max.rawValue,
                                         AVNumberOfChannelsKey: 1,
                                         AVEncoderBitRateKey: 16000,
                                         AVSampleRateKey: 16000]

    do {
        soundRecorder = try AVAudioRecorder(url: audioFileName, settings: recordSettings)
        soundRecorder?.delegate = self
        soundRecorder?.prepareToRecord()
    } catch {
       print(error)
    }
}

func setUpPlayer() {
    let audioFileName = getDocDirector().appendingPathComponent(fileName)
    print("file name:\(audioFileName)")
    do {
        soundPlayer = try AVAudioPlayer(contentsOf: audioFileName)
        soundPlayer?.delegate = self
        soundPlayer?.prepareToPlay()
        soundPlayer?.volume = 1.0
    } catch {
        print(error)
    }
}

@IBAction func recordAction(_ sender: Any) {
    if recordBtn.titleLabel?.text == "Record" {
        soundRecorder?.record()
        recordBtn.setTitle("Stop", for: .normal)
        playBtn.isEnabled = false
    } else {
        soundRecorder?.stop()
        recordBtn.setTitle("Record", for: .normal)
        playBtn.isEnabled = false
    }
}

因此文件保存在此目录中:

 file:///var/mobile/Containers/Data/Application/id-numberof mine/Documents/audioFile.m4a

当我播放它时,它工作正常。 我的问题是我如何在iTunes中查看它或从我的PC / Mac中检索它

0 个答案:

没有答案