0

I received video from node sever in chunks of data. But video does not play in AVPlayer. Here is my code.

           let videoUrl = http://staging.teemo.me/api/video/stream/sample12.MOV

 playVideo(path:videoUrl, self)

      func playVideo(path:String, controller:UIViewController){
                let yourFinalVideoURL = path
                try! AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, with: [])
                if (yourFinalVideoURL != "") {
                    let player = AVPlayer(url: NSURL(fileURLWithPath: yourFinalVideoURL) as URL)
                    let playerController = AVPlayerViewController()
                    playerController.player = player
                    controller.present(playerController, animated: true) {
                        //player.play()
                        if #available(iOS 10.0, *) {
                            player.playImmediately(atRate: 1.0)
                        } else {
                            player.play()
                        }
                    }
                }
              }
Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Shahbaz Akram
  • 1,598
  • 3
  • 28
  • 45
  • Your url string is not secure. So I suggest you to check [here](http://stackoverflow.com/questions/30731785/how-do-i-load-an-http-url-with-app-transport-security-enabled-in-ios-9) – ridvankucuk Mar 15 '17 at 15:26

1 Answers1

0

The follow code works for me:

let videoURL = URL(string: "Some url")
let player = AVPlayer(url: videoURL!)
let playerViewController = AVPlayerViewController()
playerViewController.player = player
self.present(playerViewController, animated: true) {
    playerViewController.player!.play()
}

However when I tried to use your url it doesn't work. I added the NSAppTransportSecurity in .plist, but it didn't work either. It is obvious that you have a problem with the url, try to change the extension of the file sample12.MOV to sample12.mp4

DiegoQ
  • 1,114
  • 11
  • 20