Мне удалось записать звук и воспроизвести его в том же виде, но когда я пытаюсь передать URL-адрес аудио в другой вид, что происходит, я передаю filePath, когда звук останавливается, используя recorder: AVAudioRecorder
URL-адреса профи
func recoderAudio() {
let recoderSettings = [AVFormatIDKey:kAudioFormatAppleLossless,
AVEncoderAudioQualityKey: AVAudioQuality.max.rawValue,
AVEncoderBitRateKey:32000,
AVNumberOfChannelsKey:2,
AVSampleRateKey:44100.0] as [String : Any]
let dirPath = NSSearchPathForDirectoriesInDomains(.documentDirectory,.userDomainMask, true)[0] as String
let recordingName = "recordedVoice.m4p"
let pathArray = [dirPath, recordingName]
self.filePath = URL(string: pathArray.joined(separator: "/"))
do {
audioRecorder = try AVAudioRecorder (url: filePath!, settings: recoderSettings)
audioRecorder.delegate = self
audioRecorder.prepareToRecord()
audioRecorder.record()
} catch {
print(error.localizedDescription)
}
}
func audioRecorderDidFinishRecording(_ recorder: AVAudioRecorder, successfully flag: Bool) {
let popupVC = self.getStoryBoard().instantiateViewController(withIdentifier: "PlayAudio") as! PlayAudio
popupVC.filePath = recorder.url
print ("recorder.url \(recorder.url)")
showPopUp(popupVC, parent: self)
}
func playSound() {
do {
var soundPlayer : AVAudioPlayer!
soundPlayer = try AVAudioPlayer(contentsOf: filePath!)
soundPlayer.delegate = self
soundPlayer.prepareToPlay()
soundPlayer.volume = 1.0
soundPlayer.play()
} catch {
print(error.localizedDescription)
}
}