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文件播放,但我需要切換到不同的視圖一次視頻已經播放完畢,我該怎麼做?任何提示將不勝感激。播放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)
}
是的,這個問題已經被添加 – Bliitzkr3ig