我正在尝试将 MPMoviePlayerController 作为 View 的 subview ,但我正在尝试使用 Swift 来做到这一点,这是我目前所做的:
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
let moviePath = NSBundle.mainBundle().pathForResource("splash", ofType: "mp4")
let movieURL = NSURL.fileURLWithPath(moviePath!)
let moviePlayer = MPMoviePlayerController(contentURL: movieURL)
NSNotificationCenter.defaultCenter().addObserver(self, selector: "moviePlayerDidFinishPlaying:" , name: MPMoviePlayerPlaybackDidFinishNotification, object: moviePlayer)
moviePlayer.controlStyle = .None
moviePlayer.scalingMode = .Fill
self.view.addSubview(moviePlayer.view)
moviePlayer.setFullscreen(true, animated: true)
moviePlayer.play()
}
func moviePlayerDidFinishPlaying(notification: NSNotification) {
}
它不工作,我在这里做错了什么?
最佳答案
您可能忘记将您的资源添加为“捆绑资源” 按照以下步骤添加:
- 在 Project Navigator 中选择您的项目根目录
- 选择“构建阶段”选项卡
- 在“捆绑资源”部分点击“+”添加您的资源
在那之后,我认为您可以让您的代码正常工作。
关于ios - 使用 MPMoviePlayerController 和 Swift 播放电影,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26650173/