mirror of
https://github.com/yattee/yattee.git
synced 2025-08-05 18:24:02 +00:00
Fix using Watch history in player queue
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import CoreMedia
|
||||
import Defaults
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
@@ -11,15 +12,28 @@ struct PlayerQueueRow: View {
|
||||
|
||||
@Default(.closePiPOnNavigation) var closePiPOnNavigation
|
||||
|
||||
@FetchRequest private var watchRequest: FetchedResults<Watch>
|
||||
|
||||
init(item: PlayerQueueItem, history: Bool = false, fullScreen: Binding<Bool> = .constant(false)) {
|
||||
self.item = item
|
||||
self.history = history
|
||||
_fullScreen = fullScreen
|
||||
_watchRequest = FetchRequest<Watch>(
|
||||
entity: Watch.entity(),
|
||||
sortDescriptors: [],
|
||||
predicate: NSPredicate(format: "videoID = %@", item.videoID)
|
||||
)
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
Group {
|
||||
Button {
|
||||
player.prepareCurrentItemForHistory()
|
||||
|
||||
if history {
|
||||
player.playHistory(item)
|
||||
player.playHistory(item, at: watchStoppedAt)
|
||||
} else {
|
||||
player.advanceToItem(item)
|
||||
player.advanceToItem(item, at: watchStoppedAt)
|
||||
}
|
||||
|
||||
if fullScreen {
|
||||
@@ -32,9 +46,21 @@ struct PlayerQueueRow: View {
|
||||
player.closePiP()
|
||||
}
|
||||
} label: {
|
||||
VideoBanner(video: item.video, playbackTime: item.playbackTime, videoDuration: item.videoDuration)
|
||||
VideoBanner(video: item.video, playbackTime: watchStoppedAt, videoDuration: watch?.videoDuration)
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
}
|
||||
}
|
||||
|
||||
private var watch: Watch? {
|
||||
watchRequest.first
|
||||
}
|
||||
|
||||
private var watchStoppedAt: CMTime? {
|
||||
guard let seconds = watch?.stoppedAt else {
|
||||
return nil
|
||||
}
|
||||
|
||||
return .secondsInDefaultTimescale(seconds)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user