尝试在xcode 7 / Swift 2中播放视频时出现许多错误

时间:2015-07-27 04:51:55

标签: xcode swift video swift2 xcode7

我在视图控制器中播放视频时遇到问题。我有一个播放按钮,当我按下它时,我想要导入xcode的视频播放。出现一些错误,我很难过。有任何想法吗?

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)

在这里,我开始收到错误,需要帮助解决抱怨的问题

        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")
    }
}

}

0 个答案:

没有答案