【发布时间】:2016-01-01 15:17:48
【问题描述】:
所以我的以下代码运行良好!适用于任何想要在 SWIFT 中制作视频的人。问题是,视频结束后,它仍保留在视频中。即使按下 Done 也没有任何反应......
如何将视频关闭回现有的视图控制器之一?
class ViewController: UIViewController {
var moviePlayer : MPMoviePlayerController?
override func viewDidLoad() {
super.viewDidLoad()
playVideo()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func playVideo() {
//Get the Video Path
//You need to put this in Project->Target->copy bundle resource for this to work
let videoPath = NSBundle.mainBundle().pathForResource("Quizzes", ofType:"mov")
//Make a URL from your path
let url = NSURL.fileURLWithPath(videoPath!)
//Initalize the movie player
moviePlayer = MPMoviePlayerController(contentURL: url)
if let player = moviePlayer {
//Make the player scale the entire view
player.view.frame = self.view.bounds
player.scalingMode = .AspectFill
//Add it as a subView to your currentView
self.view.addSubview(player.view)
//Play the video
player.prepareToPlay()
}
else {
print("Movie player couldn't be initialized")
}
}
【问题讨论】:
标签: ios swift video media-player mplayer