我正在使用MPMoviePlayerController播放視頻。我想在視頻播放結束後關閉視頻。這裏是我的代碼:當播放完成後關閉視頻Swift
import UIKit
import MediaPlayer
class programViewController: UIViewController {
var moviePlayer : MPMoviePlayerController?
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
playVideo("video", type: "mov")
}
func playVideo(navn:String, type:String) {
let path = NSBundle.mainBundle().pathForResource(navn, ofType: type)
let url = NSURL.fileURLWithPath(path!)
moviePlayer = MPMoviePlayerController(contentURL: url)
if let player = moviePlayer {
player.view.frame = self.view.bounds
player.prepareToPlay()
player.scalingMode = .AspectFit
player.shouldAutoplay = true
player.fullscreen = false
self.view.addSubview(player.view)
}
}
}
我寫了 「playerPlaybackDidFinish」 FUNC裏面有什麼? – vladasha
在我的理解中,你應該像這樣呈現moviePlayer:self.presentViewController(mv,animated:ture,completion:nil) – Ramis
然後解僱像這樣:moviePlayer.dismissViewControllerAnimated(true,completion:nil) – Ramis