使用 xCode 7.3 从 swift 2 中的 URL 播放视频文件(mp4 文件)? [英] Play video file (mp4 file) from an URL in swift 2 with xCode 7.3?

查看:46
本文介绍了使用 xCode 7.3 从 swift 2 中的 URL 播放视频文件(mp4 文件)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试从 URL 播放 mp4 文件.代码如下:

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

我在 viewDidAppear 函数中调用了它:

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.

非常感谢你

推荐答案

您是否已将相关条目添加到 info.ptlist 中?

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

IOS 将要求您在应用程序的 info.ptlist 中添加一个条目,以便从 URLS 流式传输视频(以及其他内容),这将防止您的应用程序阻止因未加密而被视为不安全的数据流.请记住,如果您在 AppStore 中发布应用,Apple 可能会要求您将所需的密钥添加到 info.ptlist,以便您只允许来自受信任 URL 的流量,而不是每个连接.

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.

为了调试,可以添加字典键App Transport Security Settings";带有允许任意加载 = YES".如下:

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

这篇关于使用 xCode 7.3 从 swift 2 中的 URL 播放视频文件(mp4 文件)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆