2022-04-17 15:03:49 +05:30
|
|
|
import CoreMedia
|
2021-12-19 22:47:04 +05:30
|
|
|
import Defaults
|
2021-10-06 01:50:09 +05:30
|
|
|
import Foundation
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct PlayerQueueRow: View {
|
|
|
|
let item: PlayerQueueItem
|
|
|
|
var history = false
|
2022-06-25 22:03:35 +05:30
|
|
|
@Binding var fullScreen: Bool
|
2021-10-06 01:50:09 +05:30
|
|
|
|
|
|
|
@EnvironmentObject<PlayerModel> private var player
|
|
|
|
|
2021-12-19 22:47:04 +05:30
|
|
|
@Default(.closePiPOnNavigation) var closePiPOnNavigation
|
|
|
|
|
2022-04-17 15:03:49 +05:30
|
|
|
@FetchRequest private var watchRequest: FetchedResults<Watch>
|
|
|
|
|
2022-06-25 22:03:35 +05:30
|
|
|
init(item: PlayerQueueItem, history: Bool = false, fullScreen: Binding<Bool> = .constant(false)) {
|
2022-04-17 15:03:49 +05:30
|
|
|
self.item = item
|
|
|
|
self.history = history
|
2022-06-25 22:03:35 +05:30
|
|
|
_fullScreen = fullScreen
|
2022-04-17 15:03:49 +05:30
|
|
|
_watchRequest = FetchRequest<Watch>(
|
|
|
|
entity: Watch.entity(),
|
|
|
|
sortDescriptors: [],
|
|
|
|
predicate: NSPredicate(format: "videoID = %@", item.videoID)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-10-06 01:50:09 +05:30
|
|
|
var body: some View {
|
2022-07-10 23:21:46 +05:30
|
|
|
Button {
|
|
|
|
player.prepareCurrentItemForHistory()
|
2021-10-06 01:50:09 +05:30
|
|
|
|
2022-07-10 23:21:46 +05:30
|
|
|
player.avPlayerBackend.startPictureInPictureOnPlay = player.playingInPictureInPicture
|
2022-05-22 02:28:11 +05:30
|
|
|
|
2022-07-10 23:21:46 +05:30
|
|
|
player.videoBeingOpened = item.video
|
2022-06-18 18:09:49 +05:30
|
|
|
|
2022-07-10 23:21:46 +05:30
|
|
|
if history {
|
|
|
|
player.playHistory(item, at: watchStoppedAt)
|
|
|
|
} else {
|
|
|
|
player.advanceToItem(item, at: watchStoppedAt)
|
|
|
|
}
|
2021-10-06 01:50:09 +05:30
|
|
|
|
2022-07-10 23:21:46 +05:30
|
|
|
if fullScreen {
|
|
|
|
withAnimation {
|
|
|
|
fullScreen = false
|
2021-10-06 01:50:09 +05:30
|
|
|
}
|
2022-07-10 23:21:46 +05:30
|
|
|
}
|
2021-12-19 22:47:04 +05:30
|
|
|
|
2022-07-10 23:21:46 +05:30
|
|
|
if closePiPOnNavigation, player.playingInPictureInPicture {
|
|
|
|
player.closePiP()
|
2021-10-06 01:50:09 +05:30
|
|
|
}
|
2022-07-10 23:21:46 +05:30
|
|
|
} label: {
|
|
|
|
VideoBanner(video: item.video, playbackTime: watchStoppedAt, videoDuration: watch?.videoDuration)
|
2021-10-06 01:50:09 +05:30
|
|
|
}
|
2022-07-10 23:21:46 +05:30
|
|
|
.buttonStyle(.plain)
|
2021-10-06 01:50:09 +05:30
|
|
|
}
|
2022-04-17 15:03:49 +05:30
|
|
|
|
|
|
|
private var watch: Watch? {
|
|
|
|
watchRequest.first
|
|
|
|
}
|
|
|
|
|
|
|
|
private var watchStoppedAt: CMTime? {
|
|
|
|
guard let seconds = watch?.stoppedAt else {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return .secondsInDefaultTimescale(seconds)
|
|
|
|
}
|
2021-10-06 01:50:09 +05:30
|
|
|
}
|