[英]SWIFT: MediaPlayer - Done Button doesn't do anything
所以我的以下代碼效果很好! 適用於希望在SWIFT中播放視頻的任何人。 問題是,視頻播放完后仍保留在視頻中。 即使按“完成”也沒有任何反應...
如何將視頻關閉回現有的View Controller之一?
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")
}
}
您已將其添加為子視圖
self.view.addSubview(player.view)
您還需要將其刪除,該代碼在哪里? 播放完畢后,請使用removeFromSuperview。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.