I'm developing an app that uses the SwiftUI .photosPicker modifier to allow the user to open videos from their photos. While many videos successfully load, one video results in the following errors occurring:
Error loading com.apple.quicktime-movie: <decode: bad range for [%@] got [offs:100 len:1229 within:0]> Error loading public.movie: <decode: bad range for [%@] got [offs:87 len:1229 within:0]> "The operation couldn’t be completed. (CoreTransferable.TransferableSupportError error 0.)"
I was able to isolate the line of code within the Transferable where this occurs to be the following:
try FileManager.default.copyItem(at: received.file, to: destination)
Is there something that I can do to ensure the app can reliably open any video?
The entire transferable struct is as follows:
import Foundation
import CoreTransferable
import UniformTypeIdentifiers
struct Video: Transferable {
let url: URL
let filename: String
static var transferRepresentation: some TransferRepresentation {
FileRepresentation(contentType: .mpeg4Movie) { video in
SentTransferredFile(video.url)
} importing: { received in
try Video.transfer(from: received)
}
FileRepresentation(contentType: .quickTimeMovie) { video in
SentTransferredFile(video.url)
} importing: { received in
try Video.transfer(from: received)
}
FileRepresentation(contentType: .avi) { video in
SentTransferredFile(video.url)
} importing: { received in
try Video.transfer(from: received)
}
FileRepresentation(contentType: .mpeg) { video in
SentTransferredFile(video.url)
} importing: { received in
try Video.transfer(from: received)
}
FileRepresentation(contentType: .mpeg2Video) { video in
SentTransferredFile(video.url)
} importing: { received in
try Video.transfer(from: received)
}
FileRepresentation(contentType: .video) { video in
SentTransferredFile(video.url)
} importing: { received in
try Video.transfer(from: received)
}
FileRepresentation(contentType: .movie) { video in
SentTransferredFile(video.url)
} importing: { received in
try Video.transfer(from: received)
}
}
static func transfer(from received: ReceivedTransferredFile) throws -> Video {
let destination = FileManager.default.temporaryDirectory.appendingPathComponent(received.file.lastPathComponent)
if FileManager.default.fileExists(atPath: destination.path) {
try FileManager.default.removeItem(at: destination)
}
try FileManager.default.copyItem(at: received.file, to: destination)
return Video(url: destination, filename: received.file.lastPathComponent)
}
}