Play video file (mp4 file) from an URL in swift 2 with xCode 7.3?

╄→гoц情女王★ 提交于 2019-12-22 10:19:56

问题


I try to play an mp4 file from an URL. Below is code:

func playVideo(url: NSURL){
        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()
    }

And I've called it in viewDidAppear function:

override func viewDidAppear(animated: Bool) {
    let fileURL = NSURL(string: "http://myserveraddress:8080/music/test.mp4")!
    playVideo(fileURL)

}

But it's not working. The result as the picture. Please check with me.

Thanks you so much


回答1:


have you added the relevant entries to the info.ptlist?

IOS will require you to add an entry to your app's info.ptlist in order to stream videos from URLS (among other things), this will prevent your app from blocking streams of data that are not considered secure as they are not encrypted. Keep in mind that if you publish the app in the AppStore Apple will probably ask you to add the needed keys to the info.ptlist so that you only allow traffic from trusted URLs, rather than every single connection.

For debugging, you can add the dictionary key "App Transport Security Settings" with "Allow Arbitrary Loads = YES". As follows:



来源:https://stackoverflow.com/questions/36305057/play-video-file-mp4-file-from-an-url-in-swift-2-with-xcode-7-3

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!