视频无法在应用中播放

问题描述 投票:0回答:1

我有一个应用程序,当用户选择一个按钮时,它会显示一个视频。代码似乎在视频播放器加载时起作用。我还修改了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()
    }
swift video avplayer swift4 avplayerviewcontroller
1个回答
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()

}
© www.soinside.com 2019 - 2024. All rights reserved.