0

i can play audio with this code.

let url = Bundle.main.url(forResource: "demo", withExtension: "mp3")
    self.movie.setMovieURL(url!)

my problem is how can i play it with, i want a recorded file to play it.

let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)

i Mean save it to FileManagere. after record a audio. i can print url out it out, after i change "demo" and "mp3". out it crash my code.

/Users/frederikfrandsen/Library/Developer/CoreSimulator/Devices/7E453A8E-A9D4-4E34-BAD3-F32DF5D8E313/data/Containers/Data/PluginKitPlugin/25D8D0CE-3F7C-46DE-A4ED-74320443A1C6/Documents/

Here some Image. sorry about my language

enter image description here

All i want is play some music from a recorded file.

  • your `url` is `nil` – JAL Oct 25 '17 at 15:22
  • AKA, the resource name you're trying to look up doesn't exist in your bundle. If your file is called `demo.wav`, the method you're using is wrong — just get `Bundle.main.url(forResource: "demo", withExtension: "wav")`. Right now it's looking for a resource named `/Users/frederikfransen/.../demo.wav`, which definitely doesn't exist in your bundle. If you're trying to load that specific file, then there's no reason to look up things in the bundle at all, and `self.movie.setMovieURL(paths[0])` should be sufficient. – Itai Ferber Oct 25 '17 at 15:25
  • wrap your url acquisition to: `if let url = Bundle.main.url(forResource: “\(urlSwift)demo”, withExtension: “wav”) { }` and debug carefully. – Hexfire Oct 25 '17 at 15:26

0 Answers0