2021-10-06 01:50:09 +05:30
|
|
|
import AVFoundation
|
2021-10-24 23:31:08 +05:30
|
|
|
import Defaults
|
2021-10-06 01:50:09 +05:30
|
|
|
import Foundation
|
|
|
|
|
2021-10-24 23:31:08 +05:30
|
|
|
struct PlayerQueueItem: Hashable, Identifiable, Defaults.Serializable {
|
|
|
|
static let bridge = PlayerQueueItemBridge()
|
|
|
|
|
2021-10-06 01:50:09 +05:30
|
|
|
var id = UUID()
|
2021-10-24 23:31:08 +05:30
|
|
|
var video: Video!
|
|
|
|
var videoID: Video.ID
|
2021-10-23 02:19:31 +05:30
|
|
|
var playbackTime: CMTime?
|
|
|
|
var videoDuration: TimeInterval?
|
2021-10-06 01:50:09 +05:30
|
|
|
|
2021-12-27 02:44:46 +05:30
|
|
|
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 23:31:08 +05:30
|
|
|
init(_ video: Video? = nil, videoID: Video.ID? = nil, playbackTime: CMTime? = nil, videoDuration: TimeInterval? = nil) {
|
2021-10-06 01:50:09 +05:30
|
|
|
self.video = video
|
2021-10-24 23:31:08 +05:30
|
|
|
self.videoID = videoID ?? video!.videoID
|
2021-10-23 02:19:31 +05:30
|
|
|
self.playbackTime = playbackTime
|
|
|
|
self.videoDuration = videoDuration
|
2021-10-06 01:50:09 +05:30
|
|
|
}
|
|
|
|
|
2021-10-23 02:19:31 +05:30
|
|
|
var duration: TimeInterval {
|
2022-02-28 02:01:17 +05:30
|
|
|
videoDuration ?? video?.length ?? .zero
|
2021-10-23 02:19:31 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
var shouldRestartPlaying: Bool {
|
2022-08-29 21:28:26 +05:30
|
|
|
guard Defaults[.watchedVideoPlayNowBehavior] == .continue else { return true }
|
|
|
|
|
2021-10-23 02:19:31 +05:30
|
|
|
guard let seconds = playbackTime?.seconds else {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2022-07-22 02:28:32 +05:30
|
|
|
return duration - seconds <= 20
|
2021-10-23 02:19:31 +05:30
|
|
|
}
|
|
|
|
|
2022-06-26 16:42:32 +05:30
|
|
|
var hasDetailsLoaded: Bool {
|
|
|
|
!video.isNil
|
|
|
|
}
|
|
|
|
|
2021-10-23 02:19:31 +05:30
|
|
|
func hash(into hasher: inout Hasher) {
|
|
|
|
hasher.combine(id)
|
|
|
|
}
|
2021-10-06 01:50:09 +05:30
|
|
|
}
|