1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-13 22:00:31 +05:30
yattee/Shared/Player/PlayerQueueRow.swift

75 lines
2.0 KiB
Swift
Raw Normal View History

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