2022-04-17 09:33:49 +00:00
|
|
|
import CoreMedia
|
2021-12-19 17:17:04 +00:00
|
|
|
import Defaults
|
2021-10-05 20:20:09 +00:00
|
|
|
import Foundation
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct PlayerQueueRow: View {
|
|
|
|
let item: PlayerQueueItem
|
|
|
|
var history = false
|
|
|
|
@Binding var fullScreen: Bool
|
|
|
|
|
|
|
|
@EnvironmentObject<PlayerModel> private var player
|
|
|
|
|
2021-12-19 17:17:04 +00:00
|
|
|
@Default(.closePiPOnNavigation) var closePiPOnNavigation
|
|
|
|
|
2022-04-17 09:33:49 +00:00
|
|
|
@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)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-10-05 20:20:09 +00:00
|
|
|
var body: some View {
|
|
|
|
Group {
|
|
|
|
Button {
|
2021-12-26 21:14:46 +00:00
|
|
|
player.prepareCurrentItemForHistory()
|
2021-10-05 20:20:09 +00:00
|
|
|
|
2022-05-21 20:58:11 +00:00
|
|
|
player.avPlayerBackend.startPictureInPictureOnPlay = player.playingInPictureInPicture
|
|
|
|
|
2021-10-05 20:20:09 +00:00
|
|
|
if history {
|
2022-04-17 09:33:49 +00:00
|
|
|
player.playHistory(item, at: watchStoppedAt)
|
2021-10-05 20:20:09 +00:00
|
|
|
} else {
|
2022-04-17 09:33:49 +00:00
|
|
|
player.advanceToItem(item, at: watchStoppedAt)
|
2021-10-05 20:20:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if fullScreen {
|
|
|
|
withAnimation {
|
|
|
|
fullScreen = false
|
|
|
|
}
|
|
|
|
}
|
2021-12-19 17:17:04 +00:00
|
|
|
|
|
|
|
if closePiPOnNavigation, player.playingInPictureInPicture {
|
|
|
|
player.closePiP()
|
|
|
|
}
|
2021-10-05 20:20:09 +00:00
|
|
|
} label: {
|
2022-04-17 09:33:49 +00:00
|
|
|
VideoBanner(video: item.video, playbackTime: watchStoppedAt, videoDuration: watch?.videoDuration)
|
2021-10-05 20:20:09 +00:00
|
|
|
}
|
|
|
|
.buttonStyle(.plain)
|
|
|
|
}
|
|
|
|
}
|
2022-04-17 09:33:49 +00:00
|
|
|
|
|
|
|
private var watch: Watch? {
|
|
|
|
watchRequest.first
|
|
|
|
}
|
|
|
|
|
|
|
|
private var watchStoppedAt: CMTime? {
|
|
|
|
guard let seconds = watch?.stoppedAt else {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return .secondsInDefaultTimescale(seconds)
|
|
|
|
}
|
2021-10-05 20:20:09 +00:00
|
|
|
}
|