Could not load some videos

Hello there!

I am trying to use PHPickerViewController to load videos, but I got a problem: I could load some videos only not all.

I refer to the existing thread, but dosen't work.

This is the code I persent PHPickerViewController
Code Block swift
var config = PHPickerConfiguration()
config.selectionLimit = 1
config.filter = .videos
config.preferredAssetRepresentationMode = .current
let picker = PHPickerViewController(configuration: config)
picker.delegate = self
present(picker, animated: true, completion: nil)


Below is the relevant implementation of the method: func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]):

Code Block swift
picker.dismiss(animated: true, completion: nil)
for result in results {
  result.itemProvider.loadFileRepresentation(forTypeIdentifier: UTType.movie.identifier) { (url, error) in
    if let error = error {
      print(error)
      return
    }
    guard let url = url else { return }
    let fileName = "\(Date().timeIntervalSince1970).\(url.pathExtension)"
    let newUrl = URL(fileURLWithPath: NSTemporaryDirectory() + fileName)
    try? FileManager.default.copyItem(at: url, to: newUrl)
    DispatchQueue.main.async {
      self.playVideo(newUrl)
    }
  }
}


Before I print error in line 5, Xcode printed 3 lines of error:
Code Block
[AXRuntimeCommon] Unknown client: TestPHPicker
[default] [ERROR] Could not create a bookmark: NSError: Cocoa 257 "The file couldn’t be opened because you don’t have permission to view it." }
Error copying file type public.movie. Error: Error Domain=NSItemProviderErrorDomain Code=-1000 "Cannot load representation of type public.movie" UserInfo={NSLocalizedDescription=Cannot load representation of type public.movie, NSUnderlyingError=0x283a4a610 {Error Domain=NSCocoaErrorDomain Code=4101 "Couldn’t communicate with a helper application." UserInfo={NSUnderlyingError=0x283a48b10 {Error Domain=PHAssetExportRequestErrorDomain Code=2 "(null)" UserInfo={NSUnderlyingError=0x283a4a550 {Error Domain=CloudPhotoLibraryErrorDomain Code=82 "Failed to download CPLResourceTypeOriginal" UserInfo=0x28219b300 (not displayed)}}}}}}


And I print error in line 5:
Code Block
Error Domain=NSItemProviderErrorDomain Code=-1000 "Cannot load representation of type public.movie" UserInfo={NSLocalizedDescription=Cannot load representation of type public.movie, NSUnderlyingError=0x283a4a610 {Error Domain=NSCocoaErrorDomain Code=4101 "Couldn’t communicate with a helper application." UserInfo={NSUnderlyingError=0x283a48b10 {Error Domain=PHAssetExportRequestErrorDomain Code=2 "(null)" UserInfo={NSUnderlyingError=0x283a4a550 {Error Domain=CloudPhotoLibraryErrorDomain Code=82 "Failed to download CPLResourceTypeOriginal" UserInfo=0x28219b300 (not displayed)}}}}}}


For some videos I can load successfully, and some videos I got error. I don't know why this happened.

I am testing this on an iPhone X iOS 14.0(18A373). Xcode 12.0 (12A7209).

Thanks for help!
Were you able to find a solution to this? I am stuck with the same issue, and more than that when it works it is awfully slow to load videos.
The error means your selected asset isn’t available locally and the picker is unable to download it from the cloud. Please make sure you have a reliable internet connection.

It is awfully slow to load videos.

It's likely that the picker is downloading and/or transcoding assets for you.

To avoid download, make sure your assets are available locally.

To avoid transcoding, you can set preferred representation mode to .current. But please don't use it unless you know your app can support arbitrary video format.
In case it helps anyone else looking here - you have to copy the file to a directory you own (as OP did) or else you will run into this error.

I don't really see any official documentation about this. I've only come across the demo app, which exclusively deals with images and live photos loaded into objects in memory.
Were you able to find a solution to this? I am stuck with the same issue.

Any solutions? I also have this issue.

Could not load some videos
 
 
Q