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
|
2022-06-18 12:39:49 +00:00
|
|
|
var fullScreen: Bool
|
2021-10-05 20:20:09 +00:00
|
|
|
|
|
|
|
@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>
|
|
|
|
|
2022-06-18 12:39:49 +00:00
|
|
|
init(item: PlayerQueueItem, history: Bool = false, fullScreen: Bool = false) {
|
2022-04-17 09:33:49 +00:00
|
|
|
self.item = item
|
|
|
|
self.history = history
|
2022-06-18 12:39:49 +00:00
|
|
|
self.fullScreen = fullScreen
|
2022-04-17 09:33:49 +00:00
|
|
|
_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
|
|
|
|
|
2022-06-18 12:39:49 +00:00
|
|
|
player.videoBeingOpened = item.video
|
|
|
|
|
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 {
|
2022-06-18 12:39:49 +00:00
|
|
|
// withAnimation {
|
|
|
|
// fullScreen = false
|
|
|
|
// }
|
2021-10-05 20:20:09 +00:00
|
|
|
}
|
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
|
|
|
}
|