yattee/Model/Segment.swift
2021-10-24 14:41:26 +02:00

47 lines
980 B
Swift

import CoreMedia
import Foundation
import SwiftyJSON
// swiftlint:disable:next final_class
class Segment: ObservableObject, Hashable {
let category: String
let segment: [Double]
let uuid: String
let videoDuration: Int
var start: Double {
segment.first!
}
var end: Double {
segment.last!
}
var endTime: CMTime {
CMTime(seconds: end, preferredTimescale: 1000)
}
init(category: String, segment: [Double], uuid: String, videoDuration: Int) {
self.category = category
self.segment = segment
self.uuid = uuid
self.videoDuration = videoDuration
}
func timeInSegment(_ time: CMTime) -> Bool {
(start ... end).contains(time.seconds)
}
func hash(into hasher: inout Hasher) {
hasher.combine(uuid)
}
static func == (lhs: Segment, rhs: Segment) -> Bool {
lhs.uuid == rhs.uuid
}
func title() -> String {
category
}
}