我尝试从URL播放mp4文件. 以下是代码: func playVideo(url: NSURL){ let player = AVPlayer(URL: url) let playerController = AVPlayerViewController() playerController.player = player self.addChildViewController(playerController) se
以下是代码:
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函数中调用它:
override func viewDidAppear(animated: Bool) { let fileURL = NSURL(string: "http://myserveraddress:8080/music/test.mp4")! playVideo(fileURL) }
但它不起作用.结果如图.请与我联系.
非常感谢
IOS将要求您在应用的info.ptlist中添加一个条目,以便从URLS(以及其他内容)流式传输视频,这样可以防止您的应用阻止因未加密而被视为安全的数据流.请记住,如果您在AppStore中发布应用程序,Apple可能会要求您将所需的密钥添加到info.ptlist,以便您只允许来自可信URL的流量,而不是每个连接.
对于调试,您可以添加字典键“App Transport Security Settings”,其中包含“Allow Arbitrary Loads = YES”.如下: