问题
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