6

enter image description here

I am trying to player an mp4 video from the local file system on an ios app. The video is about an hour long and can be played on quicktime. I am able to play an mp4 if it is from the web (NSURL(string: "http:domain.com/vid.mp4")). I am playing the video like below:

    let steamingURL:NSURL = NSURL(string: video.filePath)! //valid path
    let player = AVPlayer(URL: steamingURL)
    player.allowsExternalPlayback = false

    PlayWorkoutViewController.playerController = AVPlayerViewController()
    PlayWorkoutViewController.playerController.player = player
    self.addChildViewController(PlayWorkoutViewController.playerController)
    self.view.addSubview(PlayWorkoutViewController.playerController.view)
    PlayWorkoutViewController.playerController.view.frame = videoContainerView.frame
    PlayWorkoutViewController.playerController.showsPlaybackControls = false
    player.play()

Do I need to change some of the settings to play the longer video? Thanks.

Alex Pelletier
  • 4,933
  • 6
  • 34
  • 58

1 Answers1

7

Check the steamingURL is nil or not first

If you want to use NSURL(string: "xxx") initialiser please check the string starts with file://, otherwise use NSURL(fileURLWithPath: "xxxx") instead.

jessex
  • 201
  • 1
  • 4
  • Oh ok I will try that once I get it to build. Thanks I bet that is the problem. – Alex Pelletier Dec 23 '15 at 04:22
  • My issue was actually the opposite. I was trying to load a video from the web and getting the same result because I was using NSURL(fileURLWithPath: "http://...") instead of NSURL(string: "http://..."). – c.dunlap May 13 '16 at 17:22
  • 2
    Hi @c.dunalp, am unable to play the video even if am using URL(string: "http://...") and my app requirement is same as yours. Pls provide any alternative...Thanks – user2552751 Jul 26 '17 at 18:38