Local Video Play on Real device Iphone

耗尽温柔 提交于 2020-01-17 07:25:49

问题


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

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

How Can I Play video on my real device? Thanks


回答1:


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!)



回答2:


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


来源:https://stackoverflow.com/questions/45854668/local-video-play-on-real-device-iphone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!