0

I get this error when I record a video on my iPhone and then try to upload the file to my application and create an AVMutableComposition. It does not work both on my iPhone and the simulator.

private func getVideo(from itemProvider: NSItemProvider, typeIdentifier: String) {
    itemProvider.loadInPlaceFileRepresentation(forTypeIdentifier: typeIdentifier) {  url, bool, error in
            
            let documentsDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first
            guard let targetURL = documentsDirectory?.appendingPathComponent(url!.lastPathComponent) else {print("could not append Path component"); return }
            
            do {
                if FileManager.default.fileExists(atPath: targetURL.path) {
                    try FileManager.default.removeItem(at: targetURL)
                }
                try FileManager.default.copyItem(at: url!, to: targetURL)
                
                self.createVideo(url:targetURL)
            } catch {
            }
        }
    }
  func createVideo(url:URL){
       var   playerAsset = AVAsset(url: url)
        print("Is video composable, \(playerAsset.isComposable)")
            do{
                try assetComp.insertTimeRange(CMTimeRange(start: CMTime.zero, duration:CMTimeMakeWithSeconds(300.0, preferredTimescale: 1) ), of: playerAsset, at: CMTime.zero)
               }catch{
                   print("\(error.localizedDescription)")
                   DispatchQueue.main.async{
                       self.errorLabel.text = "\(error)"}
                  print("\(error)")
                }
        }

After I upload the video I try to create an AVMutableComposition and that is where I get this error.

Any help or even hints would be greatly appreciated.

Thanks,

  • in which line does it throw this error? and are you sure the file fully saved before you try to read it? – timbre timbre Aug 15 '22 at 17:29
  • Yeah the file is fully saved on my device. The catch statement of the createVideo throws the error. – ItsAlwaysThere Aug 29 '22 at 17:00
  • If I switch out to loadFileRepresentation it works however, this takes a long time as I am working with videos of 1hr length. The weird thing is it works some of the time and other times it doesn't and other individuals running the code have trouble replicating it – ItsAlwaysThere Aug 29 '22 at 17:01

0 Answers0