我希望从本地库播放视频到我的MPMoviePlayerController。 如果我将视频放到我的捆绑包中,它将起作用
let selURL = "sample"
let pathToEx1 = NSBundle.mainBundle().pathForResource( selURL, ofType: "mp4")
但如果它来自图书馆则不是。
let selURL = "file:///Users/Vinod/Library/Developer/CoreSimulator/Devices/G3G533F0-E16A-40DB-A6F1-GH67GFR89AF/data/Media/DCIM/100APPLE/sample.mp4"
let pathToEx1 = NSBundle.mainBundle().pathForResource( selURL, ofType: "mp4")
第二个代码失败。如何从图库或我的文件夹中运行视频?
答案 0 :(得分:0)
要使用用户的照片/视频库,请使用UIImagePickerController,您将获得视频网址:
@IBAction func selectImageFromPhotoLibrary(sender: AnyObject) {
imagePickerController.sourceType = .photoLibrary
imagePickerController.delegate = self
imagePickerController.mediaTypes = ["public.movie"]
present(imagePickerController, animated: true, completion: nil)
}
extension ViewController: UIImagePickerControllerDelegate {
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
let videoURL = info[UIImagePickerControllerReferenceURL] as? NSURL
}
}
否则,如果您正在阅读和编写视频而不是将它们保存到图片库中,那么很可能会将它们放在文档目录中,因为iOS是沙盒,而且您可以写入很少的地方。