-4
var audioPath = NSURL(fileURLWithPath: Bundle.main.path(forResource: "vellipomaakey", ofType: "mp3")!).  

fatal error: unexpectedly found nil while unwrapping an Optional value

Claudio Redi
  • 67,454
  • 15
  • 130
  • 155
  • Possible duplicate of [What does "fatal error: unexpectedly found nil while unwrapping an Optional value" mean?](https://stackoverflow.com/questions/32170456/what-does-fatal-error-unexpectedly-found-nil-while-unwrapping-an-optional-valu) – xoudini Sep 22 '17 at 19:41

2 Answers2

2

Did you see it in the Copy Bundle Resources section? If not, press on + sign to add that mp3 file. enter image description here

Danh Huynh
  • 2,337
  • 1
  • 15
  • 18
0

You are force unwrapping your optional, consider the following:

if let res = Bundle.main.path(forResource: "vellipomaakey", ofType: "mp3") {
    var audioPath = NSURL(fileURLWithPath:res)
}

This will most likely take away your run time error but it won't solve your issue. The problem here is that the resource you are trying to load is not being found, so Bundle.main.path(forResource: "vellipomaakey, ofType: "mp3") is returning nil.

Graham
  • 7,431
  • 18
  • 59
  • 84
Daniel Ormeño
  • 2,743
  • 2
  • 25
  • 30