VPCamera3/SwiftProject/SwiftProject/Project/Util/ZZHHelper.swift
2024-04-12 13:42:10 +08:00

91 lines
2.7 KiB
Swift

//
// ZZHHelper.swift
// SwiftProject
//
// Created by aaa on 2024/3/11.
//
import Foundation
import AVFoundation
class ZZHHelper {
class func formatVideoTime(second:Int) -> String {
let allTime: Int = second
var hours = 0
var minutes = 0
var seconds = 0
var hoursText = ""
var minutesText = ""
var secondsText = ""
hours = allTime / 3600
hoursText = hours > 9 ? "\(hours)" : "0\(hours)"
minutes = allTime % 3600 / 60
minutesText = minutes > 9 ? "\(minutes)" : "0\(minutes)"
seconds = allTime % 3600 % 60
secondsText = seconds > 9 ? "\(seconds)" : "0\(seconds)"
if hoursText == "00" {
return "\(minutesText):\(secondsText)"
}else{
return "\(hoursText):\(minutesText):\(secondsText)"
}
}
//MARK:
class func isSpatialVideo(asset: AVAsset) -> Bool {
// for track in asset.tracks {
// if track.mediaType == .video {
// for formatDesc in track.formatDescriptions {
// let dic = CMFormatDescriptionGetExtensions(formatDesc as! CMFormatDescription) as! Dictionary<String, Any>
// print("fromatdesc:\n\(dic)\n\n")
// }
// }
// }
// return false
let metadata = asset.metadata(forFormat: AVMetadataFormat.quickTimeMetadata)
let isSpatialVideo = metadata.contains { item in
print("item:\n\(item) \n\n\n")
if let identifier = item.identifier?.rawValue {
return (identifier == "mdta/com.apple.quicktime.spatial.format-version") || (identifier == "mdta/com.apple.quicktime.spatial-overcapture.quality-scoring-version")
}
return false
}
return isSpatialVideo
}
//
class func setNowTimeToUserDefaultWithKey(_ key:String) {
UserDefaults.standard.setValue(Date.now, forKey: key)
UserDefaults.standard.synchronize()
}
//
class func getSecFromUserDefaultByKey(_ key:String)->TimeInterval {
var sec:TimeInterval = 0
let date = UserDefaults.standard.value(forKey: key)
if let d = date as? Date{
sec = DateInterval.init(start: d, end: Date.now).duration
}
return sec
}
class func getVersion()->String {
var verStr = "version"
if let appVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String {
verStr = "version \(appVersion)"
} else {
}
return verStr
}
}