Hi everyone I am 15 years old boy who struggles with the ability to play sound in my iOS app...So here are some lines that I've already tried and everytime I build the app I just get some errors...
01. var audioPlayer = AVAudioPlayer()
02. let audioPath = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("myFile", ofType:
"mp3"))03. audioPlayer = AVAudioPlayer(contentsOfURL: audioPath, error: nil)
04. audioPlayer.delegate = self
05. audioPlayer.prepareToPlay()
06. audioPlayer.play()
Xcode 7.0 beta(7A120f) says on line:
02. Value of optional type "String?" not unwrapped. (If I try to fix it I get another error witch has nothing in common with this line of code...And I am like WHAAAAT?)
04. Cannot assign a value.
Here's another code I've tried(simular to the first one):
var player : AVAudioPlayer! = nil //Initialization
@IBAction func playMyFile(sender: AnyObject?){
let path = NSBundle.mainBundle().pathForResource("myFile", ofType:"mp3")
let fileURL = NSURL(fileURLWithPath: path)
player = AVAudioPlayer(contentsOfURL: fileURL, error: nil)
player.prepareToPlay()
player.delegate = self
player.play()
}
I get the same errors on:
05. Value of optional type "String?" not unwrapped.
08. Cannot assign value.
Any ideas...I am really sorry if the question is really stupid but I tried everything and search the net, but nothing. Xcode gives me those mad errors and I decided to ask the PRO'S so...Thanks for the time and the help!!!