播放 mp4 文件然后切换到视图控制器,文件播放正常但无法弄清楚切换到另一个视图的代码
play a mp4 file and then switch to a view controller, file plays fine but cannot figure out the code to switch to another view
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)
}
你所说的 "switching" 是什么意思?能具体点吗?
如果您想关闭页面,请执行以下操作:
如果它在导航控制器中:
self.navigationController?.popViewControllerAnimated(true)
如果出现:
self.dismissViewControllerAnimated(true, completion: nil)
如果你想呈现另一个视图控制器:
如果它在导航控制器中:
self.navigationController?.pushViewController(yourViewController, animated: true)
如果要模态呈现:
self.presentViewController(vc, animated: true, completion: nil)
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)
}
你所说的 "switching" 是什么意思?能具体点吗?
如果您想关闭页面,请执行以下操作:
如果它在导航控制器中:
self.navigationController?.popViewControllerAnimated(true)
如果出现:
self.dismissViewControllerAnimated(true, completion: nil)
如果你想呈现另一个视图控制器:
如果它在导航控制器中:
self.navigationController?.pushViewController(yourViewController, animated: true)
如果要模态呈现:
self.presentViewController(vc, animated: true, completion: nil)