|
|
|
@ -216,7 +216,7 @@ extension DraftAttachment {
|
|
|
|
|
options.isNetworkAccessAllowed = true
|
|
|
|
|
PHImageManager.default().requestExportSession(forVideo: asset, options: options, exportPreset: AVAssetExportPresetHighestQuality) { exportSession, info in
|
|
|
|
|
if let exportSession {
|
|
|
|
|
Self.exportVideoData(session: exportSession, completion: completion)
|
|
|
|
|
Self.exportVideoData(session: exportSession, features: features, completion: completion)
|
|
|
|
|
} else if let error = info?[PHImageErrorKey] as? Error {
|
|
|
|
|
completion(.failure(.videoExport(error)))
|
|
|
|
|
} else {
|
|
|
|
@ -242,7 +242,7 @@ extension DraftAttachment {
|
|
|
|
|
completion(.failure(.noVideoExportSession))
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
Self.exportVideoData(session: session, completion: completion)
|
|
|
|
|
Self.exportVideoData(session: session, features: features, completion: completion)
|
|
|
|
|
} else {
|
|
|
|
|
let fileData: Data
|
|
|
|
|
do {
|
|
|
|
@ -300,9 +300,12 @@ extension DraftAttachment {
|
|
|
|
|
return (data, type)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static func exportVideoData(session: AVAssetExportSession, completion: @escaping (Result<(Data, UTType), ExportError>) -> Void) {
|
|
|
|
|
private static func exportVideoData(session: AVAssetExportSession, features: InstanceFeatures, completion: @escaping (Result<(Data, UTType), ExportError>) -> Void) {
|
|
|
|
|
session.outputFileType = .mp4
|
|
|
|
|
session.outputURL = FileManager.default.temporaryDirectory.appendingPathComponent("exported_video_\(UUID())").appendingPathExtension("mp4")
|
|
|
|
|
if let configuration = features.mediaAttachmentsConfiguration {
|
|
|
|
|
session.fileLengthLimit = Int64(configuration.videoSizeLimit)
|
|
|
|
|
}
|
|
|
|
|
session.exportAsynchronously {
|
|
|
|
|
guard session.status == .completed else {
|
|
|
|
|
completion(.failure(.videoExport(session.error!)))
|
|
|
|
|