xcode - found nil while unwrapping an Optional value when trying to play a sound -
i trying play sound in os x app has been built in swift.
i getting following error:
fatal error: unexpectedly found nil while unwrapping optional value
the line of code in question is:
let bgmusicurl:nsurl = nsbundle.mainbundle().urlforresource("emptytrash", withextension: "aif")!
however when call method prepare , play sound:
func playsound() { let bgmusicurl:nsurl = nsbundle.mainbundle().urlforresource("emptytrash", withextension: "aif")! backgroundmusicplayer = try! avaudioplayer(contentsofurl: bgmusicurl) backgroundmusicplayer.numberofloops = -1 backgroundmusicplayer.preparetoplay() backgroundmusicplayer.play() }
i error. going on?
i declare this:
var backgroundmusicplayer:avaudioplayer = avaudioplayer()
a file part of project doesn't have part of target, means won't copied application bundle.
to see "target membership", can open sidebar on right side (file inspector) of window. see viewing properties of file more information.
Comments
Post a Comment