1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-15 23:00:32 +05:30
yattee/Model/Player/PlayerQueueItem.swift

52 lines
1.3 KiB
Swift
Raw Normal View History

import AVFoundation
import Defaults
import Foundation
struct PlayerQueueItem: Hashable, Identifiable, Defaults.Serializable {
static let bridge = PlayerQueueItemBridge()
var id = UUID()
var video: Video!
var videoID: Video.ID
var playbackTime: CMTime?
var videoDuration: TimeInterval?
static func from(_ watch: Watch, video: Video? = nil) -> Self {
.init(
video,
videoID: watch.videoID,
playbackTime: CMTime.secondsInDefaultTimescale(watch.stoppedAt),
videoDuration: watch.videoDuration
)
}
init(_ video: Video? = nil, videoID: Video.ID? = nil, playbackTime: CMTime? = nil, videoDuration: TimeInterval? = nil) {
self.video = video
self.videoID = videoID ?? video!.videoID
self.playbackTime = playbackTime
self.videoDuration = videoDuration
}
var duration: TimeInterval {
2022-02-28 02:01:17 +05:30
videoDuration ?? video?.length ?? .zero
}
var shouldRestartPlaying: Bool {
guard Defaults[.watchedVideoPlayNowBehavior] == .continue else { return true }
guard let seconds = playbackTime?.seconds else {
return false
}
2022-07-22 02:28:32 +05:30
return duration - seconds <= 20
}
2022-06-26 16:42:32 +05:30
var hasDetailsLoaded: Bool {
!video.isNil
}
func hash(into hasher: inout Hasher) {
hasher.combine(id)
}
}