xcode, swift viewcontroller bug

Question

I wrote the code in x code however, I'm getting some errors.

This is the line of code that the error is pointing to:

try player = AVAudioPlayer(contentsOf: NSURL (fileURLWithPath: audioPath!) as URL)

Thread1 Break point1

All code

import UIKit
import AVFoundation

class ViewController: UIViewController {

    var player:AVAudioPlayer = AVAudioPlayer()


    @IBAction func Play(_ sender: Any) {
        player.play()
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

        do
        {
             let audioPath = Bundle.main.path(forResource: "song", ofType: "m4a")
            try player = AVAudioPlayer(contentsOf: NSURL (fileURLWithPath: audioPath!) as URL)

        }
        catch
        {
            //error
        }

    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

}

error self tw1.ViewController 0x00007fce5841a230 audioPath String? nil none


Show source
| xcode   | swift   | uiviewcontroller   2017-01-06 20:01 0 Answers

Answers ( 0 )

◀ Go back