import AVFoundation
import UIKit
import AVKit
class Class1: AVPlayerViewController, AVPlayerViewControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
}
func playVideo() {
if let path = NSBundle.mainBundle().pathForResource("output_aV7EL0", ofType: "mp4") {
let url = NSURL(fileURLWithPath: path)
player = AVPlayer(URL: url)
player?.play()
}
else {
print("Oops, something wrong when playing video.mp4")
}
}
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
playVideo()
}
func AVPlayerDidFinishPlaying(player: AVAudioPlayer!, successfully flag: Bool) {
if player.playing {
player.stop()
}
}
}
我已经获得了mp4文件但是我需要在视频播放完毕后切换到不同的视图,我该怎么做?任何提示将不胜感激。
func playVideo(){
if let path = NSBundle.mainBundle().pathForResource("output_aV7EL0", ofType: "mp4") {
let url = NSURL(fileURLWithPath: path)
player = AVPlayer(URL: url)
player?.play()
self.dismissViewControllerAnimated(true, completion: nil)
self.presentViewController(viewcontrollerToPresent: GameViewController1, animated: true, completion: nil)
}
答案 0 :(得分:1)
“切换”到另一个视图是什么意思?你能更具体一点吗?
如果要关闭页面请执行以下操作:
如果它在导航控制器中:
self.navigationController?.popViewControllerAnimated(true)
如果出现:
self.dismissViewControllerAnimated(true, completion: nil)
如果要呈现另一个视图控制器:
如果它在导航控制器中:
self.navigationController?.pushViewController(yourViewController, animated: true)
如果您想以模态方式呈现它:
self.presentViewController(vc, animated: true, completion: nil)