xcode - 播放 mp4 文件,然后切换到 View Controller ,文件播放正常,但无法找出切换到另一个 View 的代码

标签 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 文件,但视频播放完毕后我需要切换到不同的 View ,我该怎么做?任何提示将不胜感激。

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

最佳答案

“切换”到不同的 View 是什么意思?能具体点吗?

如果您想关闭页面,请执行以下操作:

  1. 如果它位于导航 Controller 中:

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

    self.dismissViewControllerAnimated(true, completion: nil)
    

如果你想展示另一个 View Controller :

  1. 如果它位于导航 Controller 中:

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

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

关于xcode - 播放 mp4 文件,然后切换到 View Controller ,文件播放正常,但无法找出切换到另一个 View 的代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33924591/

相关文章:

ios - 调试器 : Xcode has killed the LLDB RPC server to allow the debugger to detach from your process. 您可能需要手动终止您的进程

swift - CallKit :- Callkit is working but the callee doesn't get the call

iOS 动画故障,Y 坐标问题

ios - 条形码扫描仪应用程序

ios - 使用 iOS 模拟器运行第一个 React Native 应用程序时未找到 index.io.bundle

ios - TMDb API 调用 - Swift

ios - 将 Kal 添加为 subview 时出现奇怪的空间问题

swift - 由于未捕获的异常 'NSInvalidArgumentException' 而终止应用程序。无法识别的选择器发送到实例

swift - 无法将类型 'MenuView' 的值分配给类型 'some View'

swift - 如何模块化和重用部分 View 和 Controller ?