2021-10-05 20:20:09 +00:00
|
|
|
import AVFoundation
|
2021-10-24 18:01:08 +00:00
|
|
|
import Defaults
|
2021-10-05 20:20:09 +00:00
|
|
|
import Foundation
|
|
|
|
|
2021-10-24 18:01:08 +00:00
|
|
|
struct PlayerQueueItem: Hashable, Identifiable, Defaults.Serializable {
|
|
|
|
static let bridge = PlayerQueueItemBridge()
|
|
|
|
|
2021-10-05 20:20:09 +00:00
|
|
|
var id = UUID()
|
2021-10-24 18:01:08 +00:00
|
|
|
var video: Video!
|
|
|
|
var videoID: Video.ID
|
2021-10-22 20:49:31 +00:00
|
|
|
var playbackTime: CMTime?
|
|
|
|
var videoDuration: TimeInterval?
|
2021-10-05 20:20:09 +00:00
|
|
|
|
2021-10-24 18:01:08 +00:00
|
|
|
init(_ video: Video? = nil, videoID: Video.ID? = nil, playbackTime: CMTime? = nil, videoDuration: TimeInterval? = nil) {
|
2021-10-05 20:20:09 +00:00
|
|
|
self.video = video
|
2021-10-24 18:01:08 +00:00
|
|
|
self.videoID = videoID ?? video!.videoID
|
2021-10-22 20:49:31 +00:00
|
|
|
self.playbackTime = playbackTime
|
|
|
|
self.videoDuration = videoDuration
|
2021-10-05 20:20:09 +00:00
|
|
|
}
|
|
|
|
|
2021-10-22 20:49:31 +00:00
|
|
|
var duration: TimeInterval {
|
|
|
|
videoDuration ?? video.length
|
|
|
|
}
|
|
|
|
|
|
|
|
var shouldRestartPlaying: Bool {
|
|
|
|
guard let seconds = playbackTime?.seconds else {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
return duration - seconds <= 10
|
|
|
|
}
|
|
|
|
|
|
|
|
func hash(into hasher: inout Hasher) {
|
|
|
|
hasher.combine(id)
|
|
|
|
}
|
2021-10-05 20:20:09 +00:00
|
|
|
}
|