问题
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