Video playback progress and restoring time for previously played

This commit is contained in:
Arkadiusz Fal
2021-10-22 22:49:31 +02:00
parent bc065e282a
commit 4307da57c5
13 changed files with 219 additions and 89 deletions

View File

@@ -4,10 +4,28 @@ import Foundation
struct PlayerQueueItem: Hashable, Identifiable {
var id = UUID()
var video: Video
var playbackTime: CMTime?
var videoDuration: TimeInterval?
init(_ video: Video) {
init(_ video: Video, playbackTime: CMTime? = nil, videoDuration: TimeInterval? = nil) {
self.video = video
self.playbackTime = playbackTime
self.videoDuration = videoDuration
}
var playerItems = [AVPlayerItem]()
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)
}
}