播放一个mp4文件,然后切换到视图控制器,文件播放正常,但无法找出切换到另一个视图的代码

时间:2015-11-25 19:08:41

标签: xcode swift xcode6

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)
    }

1 个答案:

答案 0 :(得分:1)

“切换”到另一个视图是什么意思?你能更具体一点吗?

如果要关闭页面请执行以下操作:

  1. 如果它在导航控制器中:

    self.navigationController?.popViewControllerAnimated(true)
    
  2. 如果出现:

    self.dismissViewControllerAnimated(true, completion: nil)
    
  3. 如果要呈现另一个视图控制器:

    1. 如果它在导航控制器中:

      self.navigationController?.pushViewController(yourViewController, animated: true)
      
    2. 如果您想以模态方式呈现它:

      self.presentViewController(vc, animated: true, completion: nil)