Local video game on a real Iphone device

Use this link. I am trying to play a video on a simulator using AVPlayerViewController . This works great on a simulator. But when I try to play it on a real device. This does not work.

 import UIKit import AVKit import AVFoundation class SafaribroserViewController: UIViewController { var playerViewController = AVPlayerViewController() var playerView = AVPlayer() override func viewDidLoad() { super.viewDidLoad() } @IBAction func hsdgfsf(_ sender: Any) { let fileURL = NSURL.init(fileURLWithPath: "/Users/macmini/Downloads/QRCodeReader-master 3/QRCodeReader/small.mp4") playerView = AVPlayer(url: fileURL as URL) playerViewController.player = playerView present(playerViewController,animated:true) { self.playerViewController.player?.play() } } 

on a real device

enter image description here

Note. - My real device is connected to a MacMini access point.

How can I play video on my real device? Thanks

0
source share
2 answers

I think you have problems with your path.

 let fileURL = NSURL.init(fileURLWithPath: "/Users/macmini/Downloads/QRCodeReader-master 3/QRCodeReader/small.mp4") 

just add small.mp4 to your package of your application project

and use this

  let urlpath = Bundle.main.path(forResource: "small", ofType: "mp4") let fileURL = NSURL.fileURL(withPath: urlpath!) 
0
source

Try this code

 let path = NSBundle.mainBundle().pathForResource("small", ofType: "mp4") let fileURL = NSURL.init(fileURLWithPath: path) if (fileURL) { print("Video url is not empty") } 

And also check out the video in Bundle Copy Resources

---> Project

  ---->Target ---->BuildPhase ---->Copy Bundle Resources-->Add small.mp4 
0
source

Source: https://habr.com/ru/post/1489799/


All Articles