3

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.

enter image description here Thanks you so much

cauchuyennhocuatoi
  • 461
  • 3
  • 8
  • 21

1 Answers1

8

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:

App transport security settings

Community
  • 1
  • 1
Daniel Ormeño
  • 2,743
  • 2
  • 25
  • 30