How to get original file URL from a LivePhoto's video asset without saving its resource locally? (iOS)

618 Views Asked by At

I've searched and found some ways where I can get the video asset/file of the LivePhoto asset. But what those methods do are as follows:

  1. They somehow get the resources(PHAssetResource) for the LivePhoto asset
  2. Select the specific video resource(PHAssetResource) from previously found resources.(Ex: resource.type==PHAssetResourceTypePairedVideo)
  3. Save the resource data to a new File(!)
  4. Get the URL for the newly created File.

But, what I want to know, is there any way I can get the URL for the originally stored file URL, without creating a new File?

[For other types of photos/videos I'm able to get the URLs of the originally stored files. The problem is with the video of the LivePhoto asset.]

1

There are 1 best solutions below

0
On

I have found a way to directly get the original URL of the file. There is no need to save the file contents in a new file. (Tested on iOS12+)

  1. We first get the file URL of associated Image of the LivePhoto.
asset.requestContentEditingInput(with: nil) { (editingInput, info) in
    if let input = editingInput, let imgUrl = input.fullSizeImageURL {
        // use imgUrl
    }
}
  1. The Video file is stored in the same directory as the image file. So, we use the Image URL but with different extension to find the Video file of the LivePhoto. The video file extension is either .mov or .MOV.
if let videoPath = (imagePath.deletingPathExtension as NSString).appendingPathExtension("MOV") {
    let videoUrl = URL(fileURLWithPath: videoPath)
    // check if file exist and use
    // If MOV(Uppercase) extension file doesn't exist check for mov(lowercase) extension similarly
}