视频无法在应用中播放

时间:2017-12-19 17:46:32

标签: swift video avplayer swift4 avplayerviewcontroller

我有一个应用程序,当用户选择一个按钮时,它会显示一个视频。代码似乎在视频播放器加载时起作用。我还修改了NSAppTransportSecurity设置以包含NSAllowsArbitraryLoads。我已经对几个视频进行了硬编码,以查看我的特定视频是否存在问题,但没有一个能够正常运行。这是代码,非常感谢任何帮助。

    @IBAction func playVideo(_ sender: Any) {
    func prepare(for segue: UIStoryboardSegue, sender: Any?) {

        let destination = segue.destination as! AVPlayerViewController
        let url = URL(string:
            "http://www.ebookfrenzy.com/ios_book/movie/movie.mov")

        if let movieURL = url {
            destination.player = AVPlayer(url: movieURL)
        }
        let player = AVPlayer(url: url!)
        let playerController = AVPlayerViewController()

        playerController.player = player
        self.addChildViewController(playerController)
        self.view.addSubview(playerController.view)
        playerController.view.frame = self.view.frame

        player.play()
    }

1 个答案:

答案 0 :(得分:3)

基本上这很好用,

func playVideo() {

    let url = URL(string: "http://www.ebookfrenzy.com/ios_book/movie/movie.mov")
    let player = AVPlayer(url: url!)
    let playerController = AVPlayerViewController()

    playerController.player = player
    self.addChildViewController(playerController)
    self.view.addSubview(playerController.view)
    playerController.view.frame = self.view.frame

    player.play()

}