看起来它是在mpmovieplayerviewcontroller启动电影播放器之前启动电影播放器。
单击完成按钮后,无法关闭之后出现的空白电影播放器。
以下是代码:
class VideoViewController: UIViewController {
var movieViewController:MPMoviePlayerViewController?
override func viewDidLoad() {
let path = NSBundle.mainBundle().pathForResource("Open Range", ofType: "mp4")
let url = NSURL.fileURLWithPath(path!);
movieViewController = MPMoviePlayerViewController(contentURL: url)
NSNotificationCenter.defaultCenter().addObserver(self,
selector:"doneButtonClick:",
name:MPMoviePlayerPlaybackDidFinishNotification,
object:nil)
NSNotificationCenter.defaultCenter().addObserver(self,
selector:"doneButtonClick:",
name:MPMoviePlayerDidExitFullscreenNotification,
object:nil)
}
override func viewDidAppear(animated: Bool) {
self.presentMoviePlayerViewControllerAnimated(movieViewController)
}
@objc func doneButtonClick(notification: NSNotification){
self.movieViewController?.moviePlayer.stop()
self.dismissMoviePlayerViewControllerAnimated()
}
}
答案 0 :(得分:0)
解决。问题是我正在进入一个单独的视图控制器,其中包含MPMoviePlayerViewController。当我将MPMoviePlayerViewController移动到我想要启动电影的视图控制器时,它在调用self.dismissMoviePlayerViewControllerAnimated()后返回到所需的视图