0

I am having trouble playing a video in my view controller. I have a play button and when I press it, I want the video which I imported into xcode to play. Having some errors come up and I am stumped. Any ideas?

import UIKit
import MediaPlayer
import AVFoundation
class AuroraViewController: UIViewController {

var moviePlayer: AVPlayer?

@IBOutlet var AuroraViewController: UIView!

@IBAction func playButtonPressed(sender: AnyObject) {

    playVideo()
}

override func viewDidLoad() {
    super.viewDidLoad()

    // Do any additional setup after loading the view.

}




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

private func playVideo() {
    if let path = NSBundle.mainBundle().pathForResource("Aurora", ofType:"mp4") {
        let url = NSURL(fileURLWithPath: path)

Here I begin to get errors and need help with what it is complaining about

        moviePlayer = AVPlayer(contentURL: url)
        self.moviePlayer = moviePlayer
        moviePlayer.view.frame = self.view.bounds
        moviePlayer.prepareToPlay()
        moviePlayer.scalingMode = .AspectFill
        view.addSubview(moviePlayer.view)
    } else {
        debugPrint("oops, something wrong when playing video.m4v")
    }
}

}
yzet00
  • 401
  • 7
  • 23
  • 1
    `AVPlayer(contentURL: url)` has changed `AVPlayer(URL: url)` and also `AVPlayer` doesn't conform an `UIView`. this code `self.moviePlayer = moviePlaye` is not make sense. – Long Pham Jul 27 '15 at 05:05
  • @longpham So what do I change in the code? – yzet00 Jul 27 '15 at 05:06
  • @ yzet00 you try from here? http://stackoverflow.com/questions/25348877/how-to-play-a-local-video-with-swift?rq=1 . Please compare your carefully code. – Long Pham Jul 27 '15 at 05:40

0 Answers0