// // VideoActivityItemSource.swift // Tusker // // Created by Shadowfacts on 3/19/24. // Copyright © 2024 Shadowfacts. All rights reserved. // import UIKit import UniformTypeIdentifiers import AVFoundation class VideoActivityItemSource: UIActivityItemProvider { private let asset: AVAsset private let url: URL private var tempURL: URL? init(asset: AVAsset, url: URL) { self.asset = asset self.url = url super.init(placeholderItem: url) } override var item: Any { if let tempURL { return tempURL } do { let data = try Data(contentsOf: url) let tempURL = FileManager.default.temporaryDirectory.appendingPathComponent(url.lastPathComponent) try data.write(to: tempURL) self.tempURL = tempURL return tempURL } catch { return url } } override func activityViewController(_ activityViewController: UIActivityViewController, dataTypeIdentifierForActivityType activityType: UIActivity.ActivityType?) -> String { return (UTType(filenameExtension: url.pathExtension) ?? .video).identifier } }