I am fairly new to this and trying to figure out the correct format to solve the error in the title. I get on the line: let audioPath = NSBundle.mainBundle().pathForResource("Pugs.m4a", ofType: nil)!
I know I must be missing something just not sure where.
import UIKit import AVFoundation
class ViewController: UIViewController {
@IBOutlet var playButton: UIButton!
var playPug = 1
var player: AVAudioPlayer!
@IBAction func playPressed(sender: AnyObject) {
let audioPath = NSBundle.mainBundle().pathForResource("Pugs.m4a", ofType: nil)!
let url = NSURL(fileURLWithPath: audioPath)
do {
if playPug == 1 {
let sound = try AVAudioPlayer(contentsOfURL: url)
player = sound
sound.play()
playPug = 2
playButton.setImage(UIImage(named:"pause_Icon.png"),forState:UIControlState.Normal)
} else {
player.pause()
playPug = 1
playButton.setImage(UIImage(named:"play_Icon.png"),forState:UIControlState.Normal)
}
} catch {
print(error)
}
}