All I am trying to do is have a view Controller that has button. When pressed it will play a video.
My code has a runtime bad instruction error. The app can build but when the button is pressed the error message comes up. The error message is in line "let videoURL = NSURL(fileURLWithPath: filePath!)".
import UIKit
import AVKit
import AVFoundation
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func playVideo(_ sender: UIButton) {
playLocalVideo()
}
func playLocalVideo(){
let filePath = Bundle.main.path(forResource: "t", ofType: "mp4")
let videoURL = NSURL(fileURLWithPath: filePath!)
let player = AVPlayer(url: videoURL as URL)
let playViewController = AVPlayerViewController()
playViewController.player = player
self.present(playViewController, animated: true) {() -> Void in playViewController.player!.play()
} } }