yattee/Model/Player/PlayerQueueItem.swift

57 lines
1.5 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-27 20:31:17 +00:00
videoDuration ?? video?.length ?? .zero
}
var shouldRestartPlaying: Bool {
guard Defaults[.watchedVideoPlayNowBehavior] == .continue else { return true }
guard let seconds = playbackTime?.seconds else {
return false
}
2022-11-12 23:07:23 +00:00
if duration <= 0 {
return false
}
2022-11-19 13:11:04 +00:00
return (seconds / duration) * 100 > Double(Defaults[.watchedThreshold])
}
2022-06-26 11:12:32 +00:00
var hasDetailsLoaded: Bool {
2022-11-10 17:11:28 +00:00
guard let video else { return false }
return !video.streams.isEmpty
2022-06-26 11:12:32 +00:00
}
func hash(into hasher: inout Hasher) {
hasher.combine(id)
}
}