Local Video Play on Real device Iphone

2019-08-25 09:10发布

Use this link I am trying to play a video on the simulator with AVPlayerViewController. That work on simulator perfectly. But when I am trying to play it on real Device. It doesn't 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()
    }
}

output on real device

enter image description here

Note:- My real device is connected to MacMini Hotspot.

How Can I Play video on my real device? Thanks

2条回答
Emotional °昔
2楼-- · 2019-08-25 09:29

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 video in Copy Bundle Resources

---> Project

  ---->Target
  ---->BuildPhase
  ---->Copy Bundle Resources-->Add small.mp4
查看更多
成全新的幸福
3楼-- · 2019-08-25 09:31

i think you have problem with your path

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

just add small.mp4 to your bundle of your app project

and use this

 let urlpath     = Bundle.main.path(forResource: "small", ofType: "mp4")
    let fileURL         = NSURL.fileURL(withPath: urlpath!)
查看更多
登录 后发表回答