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,