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-12-26 21:14:46 +00:00
|
|
|
static func from(_ watch: Watch, video: Video? = nil) -> Self {
|
|
|
|
.init(
|
|
|
|
video,
|
|
|
|
videoID: watch.videoID,
|
|
|
|
playbackTime: CMTime.secondsInDefaultTimescale(watch.stoppedAt),
|
|
|
|
videoDuration: watch.videoDuration
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
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 {
|
2022-02-27 20:31:17 +00:00
|
|
|
videoDuration ?? video?.length ?? .zero
|
2021-10-22 20:49:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var shouldRestartPlaying: Bool {
|
2022-08-29 15:58:26 +00:00
|
|
|
guard Defaults[.watchedVideoPlayNowBehavior] == .continue else { return true }
|
|
|
|
|
2021-10-22 20:49:31 +00:00
|
|
|
guard let seconds = playbackTime?.seconds else {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2022-07-21 20:58:32 +00:00
|
|
|
return duration - seconds <= 20
|
2021-10-22 20:49:31 +00:00
|
|
|
}
|
|
|
|
|
2022-06-26 11:12:32 +00:00
|
|
|
var hasDetailsLoaded: Bool {
|
|
|
|
!video.isNil
|
|
|
|
}
|
|
|
|
|
2021-10-22 20:49:31 +00:00
|
|
|
func hash(into hasher: inout Hasher) {
|
|
|
|
hasher.combine(id)
|
|
|
|
}
|
2021-10-05 20:20:09 +00:00
|
|
|
}
|