add video import duration limit
This commit is contained in:
1 parent
38c6d06a0e
commit
2148a348da
4 files changed
+62
-39
No files matched your search
@@ -8,6 +8,7 @@
|
||||
import Foundation
|
||||
import AVFoundation
|
||||
import UIKit
|
||||
import CoreTransferable
|
||||
|
||||
extension CGImage {
|
||||
var png: Data? {
|
||||
@@ -23,7 +24,55 @@ extension CGImage {
|
||||
}
|
||||
}
|
||||
|
||||
struct Movie: Transferable {
|
||||
let url: URL
|
||||
|
||||
static var transferRepresentation: some TransferRepresentation {
|
||||
FileRepresentation(contentType: .movie) { movie in
|
||||
SentTransferredFile(movie.url)
|
||||
} importing: { received in
|
||||
let videoFolder = SymHandler.getDocumentsDirectory().appendingPathComponent("Videos", conformingTo: .directory)
|
||||
if !FileManager.default.fileExists(atPath: videoFolder.path()) {
|
||||
try? FileManager.default.createDirectory(at: videoFolder, withIntermediateDirectories: true)
|
||||
}
|
||||
let copy = videoFolder.appending(path: "\(UUID()).mp4")
|
||||
|
||||
if FileManager.default.fileExists(atPath: copy.path()) {
|
||||
try FileManager.default.removeItem(at: copy)
|
||||
}
|
||||
|
||||
try FileManager.default.copyItem(at: received.file, to: copy)
|
||||
return Self.init(url: copy)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum LoadState {
|
||||
case unknown, loading, loaded(Movie), failed
|
||||
}
|
||||
|
||||
struct LoadInfo: Identifiable, Equatable {
|
||||
static func == (lhs: LoadInfo, rhs: LoadInfo) -> Bool {
|
||||
lhs.id == rhs.id
|
||||
}
|
||||
|
||||
var id = UUID()
|
||||
var autoReverses: Bool = false
|
||||
var loadState: LoadState
|
||||
}
|
||||
|
||||
class VideoHandler {
|
||||
static let MaxDurationSecs = 12.0
|
||||
|
||||
static func isVideoTooLong(at url: URL) -> Bool {
|
||||
let asset = AVAsset(url: url)
|
||||
|
||||
let duration = asset.duration
|
||||
let durationTime = CMTimeGetSeconds(duration)
|
||||
|
||||
return durationTime > MaxDurationSecs
|
||||
}
|
||||
|
||||
static func createCaml(from url: URL, autoReverses: Bool) throws -> URL {
|
||||
// copy the resources
|
||||
let descrURL = SymHandler.getDocumentsDirectory().appendingPathComponent(UUID().uuidString, conformingTo: .directory)
|
||||
|
||||
Reference in new issue
Block a user