Jobs Jobs - 10 months ago 77
iOS Question

Video playing on xcode simulator but not on device

I had created a page for my project that has a video (2.1 Mb/480p) that plays on loop. The video plays on my simulator, but not when I'm sideloading the app onto an iPhone device. I've checked out multiple posts with the same question but none of the solutions have worked for me so far. What could be causing this issue? How can I resolve it?

My video is stored locally. Here is the relevant source code that plays my video:

override func viewDidAppear(animated: Bool) {

let fileUrl = NSURL(fileURLWithPath: "/Users/User/Desktop/Project_XYZ/Pultz/11005472.mp4")
playerView = AVPlayer(URL: fileUrl)

let playerLayer = AVPlayerLayer(player: playerView)
playerLayer.frame = videoContainer.frame
playerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill

//playerViewController.player = playerView


NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(WorkoutDashboardViewController.restart), name: AVPlayerItemDidPlayToEndTimeNotification, object: self.playerView.currentItem)


P.S. The video I'm using is a free watermarked vid I got off the internet. Could this be a probable cause?


Try to change this:

let fileUrl = NSURL(fileURLWithPath: "/Users/User/Desktop/Project_XYZ/Pultz/11005472.mp4")


let fileUrl = NSURL(fileURLWithPath:  NSBundle.mainBundle().pathForResource("11005472", ofType: "mp4"))

In your iPhone you have a different file system. You can't use the same paths that you use on your computer/Simulator.