mirror of
https://github.com/yattee/yattee.git
synced 2024-12-22 21:43:41 +00:00
Model improvements
This commit is contained in:
parent
7b48041165
commit
f607e6e276
@ -78,7 +78,7 @@ struct FixtureEnvironmentObjectsModifier: ViewModifier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private var playerControls: PlayerControlsModel {
|
private var playerControls: PlayerControlsModel {
|
||||||
PlayerControlsModel(presentingControls: true, presentingControlsOverlay: false, player: player)
|
PlayerControlsModel(presentingControls: true)
|
||||||
}
|
}
|
||||||
|
|
||||||
private var subscriptions: SubscriptionsModel {
|
private var subscriptions: SubscriptionsModel {
|
||||||
|
@ -1,11 +1,19 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
final class NetworkStateModel: ObservableObject {
|
final class NetworkStateModel: ObservableObject {
|
||||||
|
static var shared = NetworkStateModel()
|
||||||
|
|
||||||
@Published var pausedForCache = false
|
@Published var pausedForCache = false
|
||||||
@Published var cacheDuration = 0.0
|
@Published var cacheDuration = 0.0
|
||||||
@Published var bufferingState = 0.0
|
@Published var bufferingState = 0.0
|
||||||
|
|
||||||
var player: PlayerModel!
|
private var player: PlayerModel! { .shared }
|
||||||
|
private let controlsOverlayModel = ControlOverlaysModel.shared
|
||||||
|
|
||||||
|
var osdVisible: Bool {
|
||||||
|
guard let player = player else { return false }
|
||||||
|
return player.isPlaying && ((player.activeBackend == .mpv && pausedForCache) || player.isSeeking)
|
||||||
|
}
|
||||||
|
|
||||||
var fullStateText: String? {
|
var fullStateText: String? {
|
||||||
guard let bufferingStateText = bufferingStateText,
|
guard let bufferingStateText = bufferingStateText,
|
||||||
@ -34,7 +42,7 @@ final class NetworkStateModel: ObservableObject {
|
|||||||
|
|
||||||
var needsUpdates: Bool {
|
var needsUpdates: Bool {
|
||||||
if let player = player {
|
if let player = player {
|
||||||
return !player.currentItem.isNil && (pausedForCache || player.isSeeking || player.isLoadingVideo || player.controls.presentingControlsOverlay)
|
return !player.currentItem.isNil && (pausedForCache || player.isSeeking || player.isLoadingVideo || controlsOverlayModel.presenting)
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
return false
|
||||||
|
@ -12,11 +12,11 @@ final class AVPlayerBackend: PlayerBackend {
|
|||||||
|
|
||||||
private var logger = Logger(label: "avplayer-backend")
|
private var logger = Logger(label: "avplayer-backend")
|
||||||
|
|
||||||
var model: PlayerModel!
|
var model: PlayerModel! { .shared }
|
||||||
var controls: PlayerControlsModel!
|
var controls: PlayerControlsModel! { .shared }
|
||||||
var playerTime: PlayerTimeModel!
|
var playerTime: PlayerTimeModel! { .shared }
|
||||||
var networkState: NetworkStateModel!
|
var networkState: NetworkStateModel! { .shared }
|
||||||
var seek: SeekModel!
|
var seek: SeekModel! { .shared }
|
||||||
|
|
||||||
var stream: Stream?
|
var stream: Stream?
|
||||||
var video: Video?
|
var video: Video?
|
||||||
@ -76,11 +76,7 @@ final class AVPlayerBackend: PlayerBackend {
|
|||||||
|
|
||||||
internal var controlsUpdates = false
|
internal var controlsUpdates = false
|
||||||
|
|
||||||
init(model: PlayerModel, controls: PlayerControlsModel?, playerTime: PlayerTimeModel?) {
|
init() {
|
||||||
self.model = model
|
|
||||||
self.controls = controls
|
|
||||||
self.playerTime = playerTime ?? PlayerTimeModel.shared
|
|
||||||
|
|
||||||
addFrequentTimeObserver()
|
addFrequentTimeObserver()
|
||||||
addInfrequentTimeObserver()
|
addInfrequentTimeObserver()
|
||||||
addPlayerTimeControlStatusObserver()
|
addPlayerTimeControlStatusObserver()
|
||||||
|
@ -13,11 +13,11 @@ final class MPVBackend: PlayerBackend {
|
|||||||
|
|
||||||
private var logger = Logger(label: "mpv-backend")
|
private var logger = Logger(label: "mpv-backend")
|
||||||
|
|
||||||
var model: PlayerModel!
|
var model: PlayerModel! { .shared }
|
||||||
var controls: PlayerControlsModel!
|
var controls: PlayerControlsModel! { .shared }
|
||||||
var playerTime: PlayerTimeModel!
|
var playerTime: PlayerTimeModel! { .shared }
|
||||||
var networkState: NetworkStateModel!
|
var networkState: NetworkStateModel! { .shared }
|
||||||
var seek: SeekModel!
|
var seek: SeekModel! { .shared }
|
||||||
|
|
||||||
var stream: Stream?
|
var stream: Stream?
|
||||||
var video: Video?
|
var video: Video?
|
||||||
@ -120,17 +120,7 @@ final class MPVBackend: PlayerBackend {
|
|||||||
client?.cacheDuration ?? 0
|
client?.cacheDuration ?? 0
|
||||||
}
|
}
|
||||||
|
|
||||||
init(
|
init() {
|
||||||
model: PlayerModel,
|
|
||||||
controls: PlayerControlsModel? = nil,
|
|
||||||
playerTime: PlayerTimeModel? = nil,
|
|
||||||
networkState: NetworkStateModel? = nil
|
|
||||||
) {
|
|
||||||
self.model = model
|
|
||||||
self.controls = controls
|
|
||||||
self.playerTime = playerTime ?? PlayerTimeModel.shared
|
|
||||||
self.networkState = networkState
|
|
||||||
|
|
||||||
clientTimer = .init(interval: .seconds(Self.timeUpdateInterval), mode: .infinite) { [weak self] _ in
|
clientTimer = .init(interval: .seconds(Self.timeUpdateInterval), mode: .infinite) { [weak self] _ in
|
||||||
self?.getTimeUpdates()
|
self?.getTimeUpdates()
|
||||||
}
|
}
|
||||||
|
@ -6,11 +6,10 @@ import Foundation
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
protocol PlayerBackend {
|
protocol PlayerBackend {
|
||||||
var model: PlayerModel! { get set }
|
var model: PlayerModel! { get }
|
||||||
var controls: PlayerControlsModel! { get set }
|
var controls: PlayerControlsModel! { get }
|
||||||
var playerTime: PlayerTimeModel! { get set }
|
var playerTime: PlayerTimeModel! { get }
|
||||||
var seek: SeekModel! { get set }
|
var networkState: NetworkStateModel! { get }
|
||||||
var networkState: NetworkStateModel! { get set }
|
|
||||||
|
|
||||||
var stream: Stream? { get set }
|
var stream: Stream? { get set }
|
||||||
var video: Video? { get set }
|
var video: Video? { get set }
|
||||||
@ -69,20 +68,20 @@ protocol PlayerBackend {
|
|||||||
|
|
||||||
extension PlayerBackend {
|
extension PlayerBackend {
|
||||||
func seek(to time: CMTime, seekType: SeekType, completionHandler: ((Bool) -> Void)? = nil) {
|
func seek(to time: CMTime, seekType: SeekType, completionHandler: ((Bool) -> Void)? = nil) {
|
||||||
seek.registerSeek(at: time, type: seekType, restore: currentTime)
|
model.seek.registerSeek(at: time, type: seekType, restore: currentTime)
|
||||||
seek(to: time, seekType: seekType, completionHandler: completionHandler)
|
seek(to: time, seekType: seekType, completionHandler: completionHandler)
|
||||||
}
|
}
|
||||||
|
|
||||||
func seek(to seconds: Double, seekType: SeekType, completionHandler: ((Bool) -> Void)? = nil) {
|
func seek(to seconds: Double, seekType: SeekType, completionHandler: ((Bool) -> Void)? = nil) {
|
||||||
let seconds = CMTime.secondsInDefaultTimescale(seconds)
|
let seconds = CMTime.secondsInDefaultTimescale(seconds)
|
||||||
seek.registerSeek(at: seconds, type: seekType, restore: currentTime)
|
model.seek.registerSeek(at: seconds, type: seekType, restore: currentTime)
|
||||||
seek(to: seconds, seekType: seekType, completionHandler: completionHandler)
|
seek(to: seconds, seekType: seekType, completionHandler: completionHandler)
|
||||||
}
|
}
|
||||||
|
|
||||||
func seek(relative time: CMTime, seekType: SeekType, completionHandler: ((Bool) -> Void)? = nil) {
|
func seek(relative time: CMTime, seekType: SeekType, completionHandler: ((Bool) -> Void)? = nil) {
|
||||||
if let currentTime = currentTime, let duration = playerItemDuration {
|
if let currentTime = currentTime, let duration = playerItemDuration {
|
||||||
let seekTime = min(max(0, currentTime.seconds + time.seconds), duration.seconds)
|
let seekTime = min(max(0, currentTime.seconds + time.seconds), duration.seconds)
|
||||||
seek.registerSeek(at: .secondsInDefaultTimescale(seekTime), type: seekType, restore: currentTime)
|
model.seek.registerSeek(at: .secondsInDefaultTimescale(seekTime), type: seekType, restore: currentTime)
|
||||||
seek(to: seekTime, seekType: seekType, completionHandler: completionHandler)
|
seek(to: seekTime, seekType: seekType, completionHandler: completionHandler)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
21
Model/Player/ControlsOverlayModel.swift
Normal file
21
Model/Player/ControlsOverlayModel.swift
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
import Defaults
|
||||||
|
import Foundation
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
final class ControlOverlaysModel: ObservableObject {
|
||||||
|
static let shared = ControlOverlaysModel()
|
||||||
|
@Published var presenting = false { didSet { handlePresentationChange() } }
|
||||||
|
|
||||||
|
private lazy var controls = PlayerControlsModel.shared
|
||||||
|
private lazy var player: PlayerModel! = PlayerModel.shared
|
||||||
|
|
||||||
|
func toggle() {
|
||||||
|
presenting.toggle()
|
||||||
|
controls.objectWillChange.send()
|
||||||
|
}
|
||||||
|
|
||||||
|
private func handlePresentationChange() {
|
||||||
|
guard let player = player else { return }
|
||||||
|
player.backend.setNeedsNetworkStateUpdates(presenting && Defaults[.showMPVPlaybackStats])
|
||||||
|
}
|
||||||
|
}
|
@ -10,7 +10,6 @@ final class PlayerControlsModel: ObservableObject {
|
|||||||
@Published var isLoadingVideo = false
|
@Published var isLoadingVideo = false
|
||||||
@Published var isPlaying = true
|
@Published var isPlaying = true
|
||||||
@Published var presentingControls = false { didSet { handlePresentationChange() } }
|
@Published var presentingControls = false { didSet { handlePresentationChange() } }
|
||||||
@Published var presentingControlsOverlay = false { didSet { handleSettingsOverlayPresentationChange() } }
|
|
||||||
@Published var presentingDetailsOverlay = false { didSet { handleDetailsOverlayPresentationChange() } }
|
@Published var presentingDetailsOverlay = false { didSet { handleDetailsOverlayPresentationChange() } }
|
||||||
var timer: Timer?
|
var timer: Timer?
|
||||||
|
|
||||||
@ -18,24 +17,21 @@ final class PlayerControlsModel: ObservableObject {
|
|||||||
private(set) var reporter = PassthroughSubject<String, Never>()
|
private(set) var reporter = PassthroughSubject<String, Never>()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
var player: PlayerModel!
|
private var player: PlayerModel! { .shared }
|
||||||
|
private var controlsOverlayModel = ControlOverlaysModel.shared
|
||||||
|
|
||||||
init(
|
init(
|
||||||
isLoadingVideo: Bool = false,
|
isLoadingVideo: Bool = false,
|
||||||
isPlaying: Bool = true,
|
isPlaying: Bool = true,
|
||||||
presentingControls: Bool = false,
|
presentingControls: Bool = false,
|
||||||
presentingControlsOverlay: Bool = false,
|
|
||||||
presentingDetailsOverlay: Bool = false,
|
presentingDetailsOverlay: Bool = false,
|
||||||
timer: Timer? = nil,
|
timer: Timer? = nil
|
||||||
player: PlayerModel? = nil
|
|
||||||
) {
|
) {
|
||||||
self.isLoadingVideo = isLoadingVideo
|
self.isLoadingVideo = isLoadingVideo
|
||||||
self.isPlaying = isPlaying
|
self.isPlaying = isPlaying
|
||||||
self.presentingControls = presentingControls
|
self.presentingControls = presentingControls
|
||||||
self.presentingControlsOverlay = presentingControlsOverlay
|
|
||||||
self.presentingDetailsOverlay = presentingDetailsOverlay
|
self.presentingDetailsOverlay = presentingDetailsOverlay
|
||||||
self.timer = timer
|
self.timer = timer
|
||||||
self.player = player ?? .shared
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func handlePresentationChange() {
|
func handlePresentationChange() {
|
||||||
@ -60,26 +56,22 @@ final class PlayerControlsModel: ObservableObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func handleSettingsOverlayPresentationChange() {
|
func handleSettingsOverlayPresentationChange() {
|
||||||
player?.backend.setNeedsNetworkStateUpdates(presentingControlsOverlay && Defaults[.showMPVPlaybackStats])
|
player?.backend.setNeedsNetworkStateUpdates(controlsOverlayModel.presenting && Defaults[.showMPVPlaybackStats])
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleDetailsOverlayPresentationChange() {}
|
func handleDetailsOverlayPresentationChange() {}
|
||||||
|
|
||||||
var presentingOverlays: Bool {
|
var presentingOverlays: Bool {
|
||||||
presentingDetailsOverlay || presentingControlsOverlay
|
presentingDetailsOverlay || controlsOverlayModel.presenting
|
||||||
}
|
}
|
||||||
|
|
||||||
func hideOverlays() {
|
func hideOverlays() {
|
||||||
presentingDetailsOverlay = false
|
presentingDetailsOverlay = false
|
||||||
presentingControlsOverlay = false
|
controlsOverlayModel.presenting = false
|
||||||
}
|
}
|
||||||
|
|
||||||
func show() {
|
func show() {
|
||||||
guard !(player?.currentItem.isNil ?? true) else {
|
guard !player.currentItem.isNil, !presentingControls else {
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
guard !presentingControls else {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,4 +124,8 @@ final class PlayerControlsModel: ObservableObject {
|
|||||||
timer?.invalidate()
|
timer?.invalidate()
|
||||||
timer = nil
|
timer = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func update() {
|
||||||
|
player?.backend.updateControls()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -58,8 +58,8 @@ final class PlayerModel: ObservableObject {
|
|||||||
@Published var presentingPlayer = false { didSet { handlePresentationChange() } }
|
@Published var presentingPlayer = false { didSet { handlePresentationChange() } }
|
||||||
@Published var activeBackend = PlayerBackendType.mpv
|
@Published var activeBackend = PlayerBackendType.mpv
|
||||||
|
|
||||||
var avPlayerBackend: AVPlayerBackend!
|
var avPlayerBackend = AVPlayerBackend()
|
||||||
var mpvBackend: MPVBackend!
|
var mpvBackend = MPVBackend()
|
||||||
#if !os(macOS)
|
#if !os(macOS)
|
||||||
var mpvController = MPVViewController()
|
var mpvController = MPVViewController()
|
||||||
#endif
|
#endif
|
||||||
@ -124,34 +124,10 @@ final class PlayerModel: ObservableObject {
|
|||||||
|
|
||||||
var accounts: AccountsModel
|
var accounts: AccountsModel
|
||||||
var comments: CommentsModel
|
var comments: CommentsModel
|
||||||
var controls: PlayerControlsModel { didSet {
|
var controls: PlayerControlsModel { .shared }
|
||||||
backends.forEach { backend in
|
var playerTime: PlayerTimeModel { .shared }
|
||||||
var backend = backend
|
var networkState: NetworkStateModel { .shared }
|
||||||
backend.controls = controls
|
var seek: SeekModel { .shared }
|
||||||
backend.controls.player = self
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
var playerTime: PlayerTimeModel { didSet {
|
|
||||||
backends.forEach { backend in
|
|
||||||
var backend = backend
|
|
||||||
backend.playerTime = playerTime
|
|
||||||
backend.playerTime.player = self
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
var networkState: NetworkStateModel { didSet {
|
|
||||||
backends.forEach { backend in
|
|
||||||
var backend = backend
|
|
||||||
backend.networkState = networkState
|
|
||||||
backend.networkState.player = self
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
var seek: SeekModel { didSet {
|
|
||||||
backends.forEach { backend in
|
|
||||||
var backend = backend
|
|
||||||
backend.seek = seek
|
|
||||||
backend.seek.player = self
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
var navigation: NavigationModel
|
var navigation: NavigationModel
|
||||||
|
|
||||||
var context: NSManagedObjectContext = PersistenceController.shared.container.viewContext
|
var context: NSManagedObjectContext = PersistenceController.shared.container.viewContext
|
||||||
@ -194,30 +170,11 @@ final class PlayerModel: ObservableObject {
|
|||||||
init(
|
init(
|
||||||
accounts: AccountsModel = AccountsModel(),
|
accounts: AccountsModel = AccountsModel(),
|
||||||
comments: CommentsModel = CommentsModel(),
|
comments: CommentsModel = CommentsModel(),
|
||||||
controls: PlayerControlsModel = PlayerControlsModel(),
|
navigation: NavigationModel = NavigationModel()
|
||||||
navigation: NavigationModel = NavigationModel(),
|
|
||||||
playerTime: PlayerTimeModel = PlayerTimeModel(),
|
|
||||||
networkState: NetworkStateModel = NetworkStateModel(),
|
|
||||||
seek: SeekModel = SeekModel()
|
|
||||||
) {
|
) {
|
||||||
self.accounts = accounts
|
self.accounts = accounts
|
||||||
self.comments = comments
|
self.comments = comments
|
||||||
self.controls = controls
|
|
||||||
self.navigation = navigation
|
self.navigation = navigation
|
||||||
self.playerTime = playerTime
|
|
||||||
self.networkState = networkState
|
|
||||||
self.seek = seek
|
|
||||||
|
|
||||||
self.avPlayerBackend = AVPlayerBackend(
|
|
||||||
model: self,
|
|
||||||
controls: controls,
|
|
||||||
playerTime: playerTime
|
|
||||||
)
|
|
||||||
self.mpvBackend = MPVBackend(
|
|
||||||
model: self,
|
|
||||||
playerTime: playerTime,
|
|
||||||
networkState: networkState
|
|
||||||
)
|
|
||||||
|
|
||||||
#if !os(macOS)
|
#if !os(macOS)
|
||||||
mpvBackend.controller = mpvController
|
mpvBackend.controller = mpvController
|
||||||
|
@ -17,7 +17,7 @@ final class SeekModel: ObservableObject {
|
|||||||
|
|
||||||
@Published var presentingOSD = false
|
@Published var presentingOSD = false
|
||||||
|
|
||||||
var player: PlayerModel!
|
var player: PlayerModel! { .shared }
|
||||||
|
|
||||||
var dismissTimer: Timer?
|
var dismissTimer: Timer?
|
||||||
|
|
||||||
|
@ -16,15 +16,7 @@ struct Buffering: View {
|
|||||||
@Default(.fullScreenPlayerControlsLayout) private var fullScreenPlayerControlsLayout
|
@Default(.fullScreenPlayerControlsLayout) private var fullScreenPlayerControlsLayout
|
||||||
|
|
||||||
var playerControlsLayout: PlayerControlsLayout {
|
var playerControlsLayout: PlayerControlsLayout {
|
||||||
fullScreenLayout ? fullScreenPlayerControlsLayout : regularPlayerControlsLayout
|
player.playingFullScreen ? fullScreenPlayerControlsLayout : regularPlayerControlsLayout
|
||||||
}
|
|
||||||
|
|
||||||
var fullScreenLayout: Bool {
|
|
||||||
#if os(iOS)
|
|
||||||
player.playingFullScreen || verticalSizeClass == .compact
|
|
||||||
#else
|
|
||||||
player.playingFullScreen
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
|
@ -1,16 +1,11 @@
|
|||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
struct NetworkState: View {
|
struct NetworkState: View {
|
||||||
@EnvironmentObject<PlayerModel> private var player
|
|
||||||
@EnvironmentObject<NetworkStateModel> private var model
|
@EnvironmentObject<NetworkStateModel> private var model
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
Buffering(state: model.fullStateText)
|
Buffering(state: model.fullStateText)
|
||||||
.opacity(visible ? 1 : 0)
|
.opacity(model.osdVisible ? 1 : 0)
|
||||||
}
|
|
||||||
|
|
||||||
var visible: Bool {
|
|
||||||
player.isPlaying && ((player.activeBackend == .mpv && model.pausedForCache) || player.isSeeking)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,68 +15,77 @@ struct Seek: View {
|
|||||||
@Default(.fullScreenPlayerControlsLayout) private var fullScreenPlayerControlsLayout
|
@Default(.fullScreenPlayerControlsLayout) private var fullScreenPlayerControlsLayout
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
Button(action: model.restoreTime) {
|
Group {
|
||||||
VStack(spacing: playerControlsLayout.osdSpacing) {
|
#if os(tvOS)
|
||||||
ProgressBar(value: model.progress)
|
content
|
||||||
.frame(maxHeight: playerControlsLayout.osdProgressBarHeight)
|
.shadow(radius: 3)
|
||||||
|
#else
|
||||||
|
Button(action: model.restoreTime) { content }
|
||||||
|
.buttonStyle(.plain)
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
.opacity(visible || YatteeApp.isForPreviews ? 1 : 0)
|
||||||
|
}
|
||||||
|
|
||||||
timeline
|
var content: some View {
|
||||||
|
VStack(spacing: playerControlsLayout.osdSpacing) {
|
||||||
|
ProgressBar(value: model.progress)
|
||||||
|
.frame(maxHeight: playerControlsLayout.osdProgressBarHeight)
|
||||||
|
|
||||||
if model.isSeeking {
|
timeline
|
||||||
|
|
||||||
|
if model.isSeeking {
|
||||||
|
Divider()
|
||||||
|
gestureSeekTime
|
||||||
|
.foregroundColor(.secondary)
|
||||||
|
.font(.system(size: playerControlsLayout.chapterFontSize).monospacedDigit())
|
||||||
|
.frame(height: playerControlsLayout.chapterFontSize + 5)
|
||||||
|
|
||||||
|
if let chapter = projectedChapter {
|
||||||
Divider()
|
Divider()
|
||||||
gestureSeekTime
|
Text(chapter.title)
|
||||||
.foregroundColor(.secondary)
|
.multilineTextAlignment(.center)
|
||||||
.font(.system(size: playerControlsLayout.chapterFontSize).monospacedDigit())
|
.font(.system(size: playerControlsLayout.chapterFontSize))
|
||||||
.frame(height: playerControlsLayout.chapterFontSize + 5)
|
.fixedSize(horizontal: false, vertical: true)
|
||||||
|
}
|
||||||
if let chapter = projectedChapter {
|
if let segment = projectedSegment {
|
||||||
|
Text(SponsorBlockAPI.categoryDescription(segment.category) ?? "Sponsor")
|
||||||
|
.font(.system(size: playerControlsLayout.segmentFontSize))
|
||||||
|
.foregroundColor(Color("AppRedColor"))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
#if !os(tvOS)
|
||||||
|
if !model.restoreSeekTime.isNil {
|
||||||
Divider()
|
Divider()
|
||||||
Text(chapter.title)
|
Label(model.restoreSeekPlaybackTime, systemImage: "arrow.counterclockwise")
|
||||||
.multilineTextAlignment(.center)
|
.foregroundColor(.secondary)
|
||||||
.font(.system(size: playerControlsLayout.chapterFontSize))
|
.font(.system(size: playerControlsLayout.chapterFontSize).monospacedDigit())
|
||||||
.fixedSize(horizontal: false, vertical: true)
|
.frame(height: playerControlsLayout.chapterFontSize + 5)
|
||||||
}
|
}
|
||||||
if let segment = projectedSegment {
|
#endif
|
||||||
Text(SponsorBlockAPI.categoryDescription(segment.category) ?? "Sponsor")
|
Group {
|
||||||
|
switch model.lastSeekType {
|
||||||
|
case let .segmentSkip(category):
|
||||||
|
Divider()
|
||||||
|
Text(SponsorBlockAPI.categoryDescription(category) ?? "Sponsor")
|
||||||
.font(.system(size: playerControlsLayout.segmentFontSize))
|
.font(.system(size: playerControlsLayout.segmentFontSize))
|
||||||
.foregroundColor(Color("AppRedColor"))
|
.foregroundColor(Color("AppRedColor"))
|
||||||
}
|
default:
|
||||||
} else {
|
EmptyView()
|
||||||
#if !os(tvOS)
|
|
||||||
if !model.restoreSeekTime.isNil {
|
|
||||||
Divider()
|
|
||||||
Label(model.restoreSeekPlaybackTime, systemImage: "arrow.counterclockwise")
|
|
||||||
.foregroundColor(.secondary)
|
|
||||||
.font(.system(size: playerControlsLayout.chapterFontSize).monospacedDigit())
|
|
||||||
.frame(height: playerControlsLayout.chapterFontSize + 5)
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
Group {
|
|
||||||
switch model.lastSeekType {
|
|
||||||
case let .segmentSkip(category):
|
|
||||||
Divider()
|
|
||||||
Text(SponsorBlockAPI.categoryDescription(category) ?? "Sponsor")
|
|
||||||
.font(.system(size: playerControlsLayout.segmentFontSize))
|
|
||||||
.foregroundColor(Color("AppRedColor"))
|
|
||||||
default:
|
|
||||||
EmptyView()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.frame(maxWidth: playerControlsLayout.seekOSDWidth)
|
|
||||||
#if os(tvOS)
|
|
||||||
.padding(30)
|
|
||||||
#else
|
|
||||||
.padding(2)
|
|
||||||
.modifier(ControlBackgroundModifier())
|
|
||||||
.clipShape(RoundedRectangle(cornerRadius: 3))
|
|
||||||
#endif
|
|
||||||
|
|
||||||
.foregroundColor(.primary)
|
|
||||||
}
|
}
|
||||||
.buttonStyle(.plain)
|
.frame(maxWidth: playerControlsLayout.seekOSDWidth)
|
||||||
.opacity(visible || YatteeApp.isForPreviews ? 1 : 0)
|
#if os(tvOS)
|
||||||
|
.padding(30)
|
||||||
|
#else
|
||||||
|
.padding(2)
|
||||||
|
.modifier(ControlBackgroundModifier())
|
||||||
|
.clipShape(RoundedRectangle(cornerRadius: 3))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
.foregroundColor(.primary)
|
||||||
}
|
}
|
||||||
|
|
||||||
var timeline: some View {
|
var timeline: some View {
|
||||||
@ -121,16 +130,7 @@ struct Seek: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var playerControlsLayout: PlayerControlsLayout {
|
var playerControlsLayout: PlayerControlsLayout {
|
||||||
fullScreenLayout ? fullScreenPlayerControlsLayout : regularPlayerControlsLayout
|
(model.player?.playingFullScreen ?? false) ? fullScreenPlayerControlsLayout : regularPlayerControlsLayout
|
||||||
}
|
|
||||||
|
|
||||||
var fullScreenLayout: Bool {
|
|
||||||
guard let player = model.player else { return false }
|
|
||||||
#if os(iOS)
|
|
||||||
return player.playingFullScreen || verticalSizeClass == .compact
|
|
||||||
#else
|
|
||||||
return player.playingFullScreen
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ struct PlayerControls: View {
|
|||||||
private var player: PlayerModel!
|
private var player: PlayerModel!
|
||||||
private var thumbnails: ThumbnailsModel!
|
private var thumbnails: ThumbnailsModel!
|
||||||
|
|
||||||
@EnvironmentObject<PlayerControlsModel> private var model
|
@ObservedObject private var model = PlayerControlsModel.shared
|
||||||
|
|
||||||
#if os(iOS)
|
#if os(iOS)
|
||||||
@Environment(\.verticalSizeClass) private var verticalSizeClass
|
@Environment(\.verticalSizeClass) private var verticalSizeClass
|
||||||
@ -34,8 +34,10 @@ struct PlayerControls: View {
|
|||||||
@Default(.playerControlsLayout) private var regularPlayerControlsLayout
|
@Default(.playerControlsLayout) private var regularPlayerControlsLayout
|
||||||
@Default(.fullScreenPlayerControlsLayout) private var fullScreenPlayerControlsLayout
|
@Default(.fullScreenPlayerControlsLayout) private var fullScreenPlayerControlsLayout
|
||||||
|
|
||||||
|
private let controlsOverlayModel = ControlOverlaysModel.shared
|
||||||
|
|
||||||
var playerControlsLayout: PlayerControlsLayout {
|
var playerControlsLayout: PlayerControlsLayout {
|
||||||
fullScreenLayout ? fullScreenPlayerControlsLayout : regularPlayerControlsLayout
|
player.playingFullScreen ? fullScreenPlayerControlsLayout : regularPlayerControlsLayout
|
||||||
}
|
}
|
||||||
|
|
||||||
init(player: PlayerModel, thumbnails: ThumbnailsModel) {
|
init(player: PlayerModel, thumbnails: ThumbnailsModel) {
|
||||||
@ -90,7 +92,7 @@ struct PlayerControls: View {
|
|||||||
buttonsBar
|
buttonsBar
|
||||||
|
|
||||||
HStack {
|
HStack {
|
||||||
if !player.currentVideo.isNil, fullScreenLayout {
|
if !player.currentVideo.isNil, player.playingFullScreen {
|
||||||
Button {
|
Button {
|
||||||
withAnimation(Self.animation) {
|
withAnimation(Self.animation) {
|
||||||
model.presentingDetailsOverlay = true
|
model.presentingDetailsOverlay = true
|
||||||
@ -160,7 +162,8 @@ struct PlayerControls: View {
|
|||||||
.offset(y: -playerControlsLayout.timelineHeight - 5)
|
.offset(y: -playerControlsLayout.timelineHeight - 5)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}.opacity(model.presentingControls && !model.presentingOverlays ? 1 : 0)
|
}
|
||||||
|
.opacity(model.presentingControls ? 1 : 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.frame(maxWidth: .infinity)
|
.frame(maxWidth: .infinity)
|
||||||
@ -193,7 +196,7 @@ struct PlayerControls: View {
|
|||||||
guard player.presentingPlayer else { return }
|
guard player.presentingPlayer else { return }
|
||||||
if value == "swipe down", !model.presentingControls, !model.presentingOverlays {
|
if value == "swipe down", !model.presentingControls, !model.presentingOverlays {
|
||||||
withAnimation(Self.animation) {
|
withAnimation(Self.animation) {
|
||||||
model.presentingControlsOverlay = true
|
controlsOverlayModel.presenting = false
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
model.show()
|
model.show()
|
||||||
@ -302,19 +305,19 @@ struct PlayerControls: View {
|
|||||||
var fullscreenButton: some View {
|
var fullscreenButton: some View {
|
||||||
button(
|
button(
|
||||||
"Fullscreen",
|
"Fullscreen",
|
||||||
systemImage: fullScreenLayout ? "arrow.down.right.and.arrow.up.left" : "arrow.up.left.and.arrow.down.right"
|
systemImage: player.playingFullScreen ? "arrow.down.right.and.arrow.up.left" : "arrow.up.left.and.arrow.down.right"
|
||||||
) {
|
) {
|
||||||
player.toggleFullscreen(fullScreenLayout)
|
player.toggleFullscreen(player.playingFullScreen)
|
||||||
}
|
}
|
||||||
#if !os(tvOS)
|
#if !os(tvOS)
|
||||||
.keyboardShortcut(fullScreenLayout ? .cancelAction : .defaultAction)
|
.keyboardShortcut(player.playingFullScreen ? .cancelAction : .defaultAction)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
private var settingsButton: some View {
|
private var settingsButton: some View {
|
||||||
button("settings", systemImage: "gearshape") {
|
button("settings", systemImage: "gearshape") {
|
||||||
withAnimation(Self.animation) {
|
withAnimation(Self.animation) {
|
||||||
model.presentingControlsOverlay.toggle()
|
controlsOverlayModel.toggle()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#if os(tvOS)
|
#if os(tvOS)
|
||||||
@ -492,14 +495,6 @@ struct PlayerControls: View {
|
|||||||
.modifier(ControlBackgroundModifier(enabled: useBackground))
|
.modifier(ControlBackgroundModifier(enabled: useBackground))
|
||||||
.clipShape(RoundedRectangle(cornerRadius: cornerRadius))
|
.clipShape(RoundedRectangle(cornerRadius: cornerRadius))
|
||||||
}
|
}
|
||||||
|
|
||||||
var fullScreenLayout: Bool {
|
|
||||||
#if os(iOS)
|
|
||||||
player.playingFullScreen || verticalSizeClass == .compact
|
|
||||||
#else
|
|
||||||
player.playingFullScreen
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct PlayerControls_Previews: PreviewProvider {
|
struct PlayerControls_Previews: PreviewProvider {
|
||||||
|
@ -47,16 +47,16 @@ struct TVControls: UIViewRepresentable {
|
|||||||
func updateUIView(_: UIView, context _: Context) {}
|
func updateUIView(_: UIView, context _: Context) {}
|
||||||
|
|
||||||
func makeCoordinator() -> TVControls.Coordinator {
|
func makeCoordinator() -> TVControls.Coordinator {
|
||||||
Coordinator(controlsArea, model: model)
|
Coordinator(controlsArea)
|
||||||
}
|
}
|
||||||
|
|
||||||
final class Coordinator: NSObject {
|
final class Coordinator: NSObject {
|
||||||
private let view: UIView
|
private let view: UIView
|
||||||
private let model: PlayerControlsModel
|
private let model: PlayerControlsModel
|
||||||
|
|
||||||
init(_ view: UIView, model: PlayerControlsModel) {
|
init(_ view: UIView) {
|
||||||
self.view = view
|
self.view = view
|
||||||
self.model = model
|
model = .shared
|
||||||
super.init()
|
super.init()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,15 +53,7 @@ struct TimelineView: View {
|
|||||||
@Default(.fullScreenPlayerControlsLayout) private var fullScreenPlayerControlsLayout
|
@Default(.fullScreenPlayerControlsLayout) private var fullScreenPlayerControlsLayout
|
||||||
|
|
||||||
var playerControlsLayout: PlayerControlsLayout {
|
var playerControlsLayout: PlayerControlsLayout {
|
||||||
fullScreenLayout ? fullScreenPlayerControlsLayout : regularPlayerControlsLayout
|
player.playingFullScreen ? fullScreenPlayerControlsLayout : regularPlayerControlsLayout
|
||||||
}
|
|
||||||
|
|
||||||
var fullScreenLayout: Bool {
|
|
||||||
#if os(iOS)
|
|
||||||
player.playingFullScreen || verticalSizeClass == .compact
|
|
||||||
#else
|
|
||||||
player.playingFullScreen
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var chapters: [Chapter] {
|
var chapters: [Chapter] {
|
||||||
|
@ -39,21 +39,13 @@ struct PlayerBackendView: View {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#if os(iOS)
|
#if os(iOS)
|
||||||
.statusBarHidden(fullScreenLayout)
|
.statusBarHidden(player.playingFullScreen)
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
var fullScreenLayout: Bool {
|
|
||||||
#if os(iOS)
|
|
||||||
player.playingFullScreen || verticalSizeClass == .compact
|
|
||||||
#else
|
|
||||||
player.playingFullScreen
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#if os(iOS)
|
#if os(iOS)
|
||||||
var controlsTopPadding: Double {
|
var controlsTopPadding: Double {
|
||||||
guard fullScreenLayout else { return 0 }
|
guard player.playingFullScreen else { return 0 }
|
||||||
|
|
||||||
if UIDevice.current.userInterfaceIdiom != .pad {
|
if UIDevice.current.userInterfaceIdiom != .pad {
|
||||||
return verticalSizeClass == .compact ? SafeArea.insets.top : 0
|
return verticalSizeClass == .compact ? SafeArea.insets.top : 0
|
||||||
@ -63,12 +55,12 @@ struct PlayerBackendView: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var controlsBottomPadding: Double {
|
var controlsBottomPadding: Double {
|
||||||
guard fullScreenLayout else { return 0 }
|
guard player.playingFullScreen else { return 0 }
|
||||||
|
|
||||||
if UIDevice.current.userInterfaceIdiom != .pad {
|
if UIDevice.current.userInterfaceIdiom != .pad {
|
||||||
return fullScreenLayout && verticalSizeClass == .compact ? SafeArea.insets.bottom : 0
|
return player.playingFullScreen && verticalSizeClass == .compact ? SafeArea.insets.bottom : 0
|
||||||
} else {
|
} else {
|
||||||
return fullScreenLayout ? SafeArea.insets.bottom : 0
|
return player.playingFullScreen ? SafeArea.insets.bottom : 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -17,7 +17,7 @@ extension VideoPlayerView {
|
|||||||
}
|
}
|
||||||
.onChanged { value in
|
.onChanged { value in
|
||||||
guard player.presentingPlayer,
|
guard player.presentingPlayer,
|
||||||
!player.controls.presentingControlsOverlay else { return }
|
!controlsOverlayModel.presenting else { return }
|
||||||
|
|
||||||
if player.controls.presentingControls, !player.musicMode {
|
if player.controls.presentingControls, !player.musicMode {
|
||||||
player.controls.presentingControls = false
|
player.controls.presentingControls = false
|
||||||
@ -83,7 +83,7 @@ extension VideoPlayerView {
|
|||||||
isVerticalDrag = false
|
isVerticalDrag = false
|
||||||
|
|
||||||
guard player.presentingPlayer,
|
guard player.presentingPlayer,
|
||||||
!player.controls.presentingControlsOverlay else { return }
|
!controlsOverlayModel.presenting else { return }
|
||||||
|
|
||||||
if viewDragOffset > 100 {
|
if viewDragOffset > 100 {
|
||||||
withAnimation(Constants.overlayAnimation) {
|
withAnimation(Constants.overlayAnimation) {
|
||||||
|
@ -12,6 +12,9 @@ struct PlayerGestures: View {
|
|||||||
singleTapAction: { singleTapAction() },
|
singleTapAction: { singleTapAction() },
|
||||||
doubleTapAction: {
|
doubleTapAction: {
|
||||||
player.backend.seek(relative: .secondsInDefaultTimescale(-10), seekType: .userInteracted)
|
player.backend.seek(relative: .secondsInDefaultTimescale(-10), seekType: .userInteracted)
|
||||||
|
},
|
||||||
|
anyTapAction: {
|
||||||
|
model.update()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -231,7 +231,7 @@ struct VideoDetails: View {
|
|||||||
} else if video.description != nil, !video.description!.isEmpty {
|
} else if video.description != nil, !video.description!.isEmpty {
|
||||||
VideoDescription(video: video, detailsSize: detailsSize)
|
VideoDescription(video: video, detailsSize: detailsSize)
|
||||||
#if os(iOS)
|
#if os(iOS)
|
||||||
.padding(.bottom, fullScreenLayout ? 10 : SafeArea.insets.bottom)
|
.padding(.bottom, player.playingFullScreen ? 10 : SafeArea.insets.bottom)
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
Text("No description")
|
Text("No description")
|
||||||
@ -243,14 +243,6 @@ struct VideoDetails: View {
|
|||||||
.padding(.horizontal)
|
.padding(.horizontal)
|
||||||
}
|
}
|
||||||
|
|
||||||
var fullScreenLayout: Bool {
|
|
||||||
#if os(iOS)
|
|
||||||
return player.playingFullScreen || verticalSizeClass == .compact
|
|
||||||
#else
|
|
||||||
return player.playingFullScreen
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
@ViewBuilder var videoProperties: some View {
|
@ViewBuilder var videoProperties: some View {
|
||||||
HStack(spacing: 2) {
|
HStack(spacing: 2) {
|
||||||
publishedDateSection
|
publishedDateSection
|
||||||
|
@ -70,17 +70,18 @@ struct VideoPlayerView: View {
|
|||||||
@Default(.seekGestureSpeed) var seekGestureSpeed
|
@Default(.seekGestureSpeed) var seekGestureSpeed
|
||||||
@Default(.seekGestureSensitivity) var seekGestureSensitivity
|
@Default(.seekGestureSensitivity) var seekGestureSensitivity
|
||||||
|
|
||||||
|
@ObservedObject internal var controlsOverlayModel = ControlOverlaysModel.shared
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
ZStack(alignment: overlayAlignment) {
|
ZStack(alignment: overlayAlignment) {
|
||||||
videoPlayer
|
videoPlayer
|
||||||
.zIndex(-1)
|
.zIndex(-1)
|
||||||
#if os(iOS)
|
#if os(iOS)
|
||||||
.gesture(player.controls.presentingControlsOverlay ? videoPlayerCloseControlsOverlayGesture : nil)
|
.gesture(controlsOverlayModel.presenting ? videoPlayerCloseControlsOverlayGesture : nil)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
overlay
|
overlay
|
||||||
}
|
}
|
||||||
.animation(nil, value: player.playerSize)
|
|
||||||
.onAppear {
|
.onAppear {
|
||||||
if player.musicMode {
|
if player.musicMode {
|
||||||
player.backend.startControlsUpdates()
|
player.backend.startControlsUpdates()
|
||||||
@ -184,20 +185,20 @@ struct VideoPlayerView: View {
|
|||||||
.offset(y: playerOffset)
|
.offset(y: playerOffset)
|
||||||
.animation(dragGestureState ? .interactiveSpring(response: 0.05) : .easeOut(duration: 0.2), value: playerOffset)
|
.animation(dragGestureState ? .interactiveSpring(response: 0.05) : .easeOut(duration: 0.2), value: playerOffset)
|
||||||
.backport
|
.backport
|
||||||
.persistentSystemOverlays(!fullScreenLayout)
|
.persistentSystemOverlays(!player.playingFullScreen)
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
var overlay: some View {
|
var overlay: some View {
|
||||||
VStack {
|
VStack {
|
||||||
if player.controls.presentingControlsOverlay {
|
if controlsOverlayModel.presenting {
|
||||||
HStack {
|
HStack {
|
||||||
HStack {
|
HStack {
|
||||||
ControlsOverlay()
|
ControlsOverlay()
|
||||||
#if os(tvOS)
|
#if os(tvOS)
|
||||||
.onExitCommand {
|
.onExitCommand {
|
||||||
withAnimation(Player.controls.animation) {
|
withAnimation(PlayerControls.animation) {
|
||||||
player.controls.hideOverlays()
|
player.controls.hideOverlays()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -210,11 +211,11 @@ struct VideoPlayerView: View {
|
|||||||
.clipShape(RoundedRectangle(cornerRadius: 4))
|
.clipShape(RoundedRectangle(cornerRadius: 4))
|
||||||
}
|
}
|
||||||
#if !os(tvOS)
|
#if !os(tvOS)
|
||||||
.frame(maxWidth: fullScreenLayout ? .infinity : player.playerSize.width)
|
.frame(maxWidth: player.playingFullScreen ? .infinity : player.playerSize.width)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !os(tvOS)
|
#if !os(tvOS)
|
||||||
if !fullScreenLayout && sidebarQueue {
|
if !player.playingFullScreen && sidebarQueue {
|
||||||
Spacer()
|
Spacer()
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -255,12 +256,12 @@ struct VideoPlayerView: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var playerWidth: Double? {
|
var playerWidth: Double? {
|
||||||
fullScreenLayout ? (UIScreen.main.bounds.size.width - SafeArea.insets.left - SafeArea.insets.right) : nil
|
player.playingFullScreen ? (UIScreen.main.bounds.size.width - SafeArea.insets.left - SafeArea.insets.right) : nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var playerHeight: Double? {
|
var playerHeight: Double? {
|
||||||
let lockedPortrait = player.lockedOrientation?.contains(.portrait) ?? false
|
let lockedPortrait = player.lockedOrientation?.contains(.portrait) ?? false
|
||||||
return fullScreenLayout ? UIScreen.main.bounds.size.height - (OrientationTracker.shared.currentInterfaceOrientation.isPortrait || lockedPortrait ? (SafeArea.insets.top + SafeArea.insets.bottom) : 0) : nil
|
return player.playingFullScreen ? UIScreen.main.bounds.size.height - (OrientationTracker.shared.currentInterfaceOrientation.isPortrait || lockedPortrait ? (SafeArea.insets.top + SafeArea.insets.bottom) : 0) : nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var playerEdgesIgnoringSafeArea: Edge.Set {
|
var playerEdgesIgnoringSafeArea: Edge.Set {
|
||||||
@ -268,7 +269,7 @@ struct VideoPlayerView: View {
|
|||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
|
|
||||||
if fullScreenLayout, UIDevice.current.orientation.isLandscape {
|
if player.playingFullScreen, UIDevice.current.orientation.isLandscape {
|
||||||
return [.vertical]
|
return [.vertical]
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -296,12 +297,12 @@ struct VideoPlayerView: View {
|
|||||||
VideoPlayerSizeModifier(
|
VideoPlayerSizeModifier(
|
||||||
geometry: geometry,
|
geometry: geometry,
|
||||||
aspectRatio: player.aspectRatio,
|
aspectRatio: player.aspectRatio,
|
||||||
fullScreen: fullScreenLayout
|
fullScreen: player.playingFullScreen
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.overlay(playerPlaceholder)
|
.overlay(playerPlaceholder)
|
||||||
#endif
|
#endif
|
||||||
.frame(maxWidth: fullScreenLayout ? .infinity : nil, maxHeight: fullScreenLayout ? .infinity : nil)
|
.frame(maxWidth: player.playingFullScreen ? .infinity : nil, maxHeight: player.playingFullScreen ? .infinity : nil)
|
||||||
.onHover { hovering in
|
.onHover { hovering in
|
||||||
hoveringPlayer = hovering
|
hoveringPlayer = hovering
|
||||||
hovering ? player.controls.show() : player.controls.hide()
|
hovering ? player.controls.show() : player.controls.hide()
|
||||||
@ -326,7 +327,7 @@ struct VideoPlayerView: View {
|
|||||||
.background(Color.black)
|
.background(Color.black)
|
||||||
|
|
||||||
#if !os(tvOS)
|
#if !os(tvOS)
|
||||||
if !fullScreenLayout {
|
if !player.playingFullScreen {
|
||||||
VideoDetails(sidebarQueue: sidebarQueue, fullScreen: $fullScreenDetails)
|
VideoDetails(sidebarQueue: sidebarQueue, fullScreen: $fullScreenDetails)
|
||||||
#if os(iOS)
|
#if os(iOS)
|
||||||
.ignoresSafeArea(.all, edges: .bottom)
|
.ignoresSafeArea(.all, edges: .bottom)
|
||||||
@ -346,7 +347,7 @@ struct VideoPlayerView: View {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
.background(((colorScheme == .dark || fullScreenLayout) ? Color.black : Color.white).edgesIgnoringSafeArea(.all))
|
.background(((colorScheme == .dark || player.playingFullScreen) ? Color.black : Color.white).edgesIgnoringSafeArea(.all))
|
||||||
#if os(macOS)
|
#if os(macOS)
|
||||||
.frame(minWidth: 650)
|
.frame(minWidth: 650)
|
||||||
#endif
|
#endif
|
||||||
@ -354,9 +355,9 @@ struct VideoPlayerView: View {
|
|||||||
.onMoveCommand { direction in
|
.onMoveCommand { direction in
|
||||||
if direction == .up {
|
if direction == .up {
|
||||||
player.controls.show()
|
player.controls.show()
|
||||||
} else if direction == .down, !player.controls.presentingControlsOverlay, !player.controls.presentingControls {
|
} else if direction == .down, !controlsOverlayModel.presenting, !player.controls.presentingControls {
|
||||||
withAnimation(Player.controls.animation) {
|
withAnimation(PlayerControls.animation) {
|
||||||
player.controls.presentingControlsOverlay = true
|
controlsOverlayModel.presenting = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -385,7 +386,7 @@ struct VideoPlayerView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if !fullScreenLayout {
|
if !player.playingFullScreen {
|
||||||
#if os(iOS)
|
#if os(iOS)
|
||||||
if sidebarQueue {
|
if sidebarQueue {
|
||||||
PlayerQueueView(sidebarQueue: true, fullScreen: $fullScreenDetails)
|
PlayerQueueView(sidebarQueue: true, fullScreen: $fullScreenDetails)
|
||||||
@ -402,19 +403,11 @@ struct VideoPlayerView: View {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.onChange(of: fullScreenLayout) { newValue in
|
.onChange(of: player.playingFullScreen) { newValue in
|
||||||
if !newValue { player.controls.hideOverlays() }
|
if !newValue { player.controls.hideOverlays() }
|
||||||
}
|
}
|
||||||
#if os(iOS)
|
#if os(iOS)
|
||||||
.statusBar(hidden: fullScreenLayout)
|
.statusBar(hidden: player.playingFullScreen)
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
var fullScreenLayout: Bool {
|
|
||||||
#if os(iOS)
|
|
||||||
return player.playingFullScreen || verticalSizeClass == .compact
|
|
||||||
#else
|
|
||||||
return player.playingFullScreen
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -459,7 +452,7 @@ struct VideoPlayerView: View {
|
|||||||
|
|
||||||
#if os(tvOS)
|
#if os(tvOS)
|
||||||
var tvControls: some View {
|
var tvControls: some View {
|
||||||
TVControls(model: playerControls, player: player, thumbnails: thumbnails)
|
TVControls(player: player, thumbnails: thumbnails)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,8 @@ struct ControlsBar: View {
|
|||||||
var detailsToggleFullScreen = false
|
var detailsToggleFullScreen = false
|
||||||
var titleLineLimit = 2
|
var titleLineLimit = 2
|
||||||
|
|
||||||
|
private let controlsOverlayModel = ControlOverlaysModel.shared
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
HStack(spacing: 0) {
|
HStack(spacing: 0) {
|
||||||
detailsButton
|
detailsButton
|
||||||
@ -63,7 +65,7 @@ struct ControlsBar: View {
|
|||||||
}
|
}
|
||||||
} else if detailsToggleFullScreen {
|
} else if detailsToggleFullScreen {
|
||||||
Button {
|
Button {
|
||||||
model.controls.presentingControlsOverlay = false
|
controlsOverlayModel.presenting = false
|
||||||
model.controls.presentingControls = false
|
model.controls.presentingControls = false
|
||||||
withAnimation {
|
withAnimation {
|
||||||
fullScreen.toggle()
|
fullScreen.toggle()
|
||||||
|
@ -137,7 +137,6 @@ struct YatteeApp: App {
|
|||||||
.environmentObject(playlists)
|
.environmentObject(playlists)
|
||||||
.environmentObject(recents)
|
.environmentObject(recents)
|
||||||
.environmentObject(search)
|
.environmentObject(search)
|
||||||
.environmentObject(seek)
|
|
||||||
.environmentObject(subscriptions)
|
.environmentObject(subscriptions)
|
||||||
.environmentObject(thumbnails)
|
.environmentObject(thumbnails)
|
||||||
.handlesExternalEvents(preferring: Set(["player", "*"]), allowing: Set(["player", "*"]))
|
.handlesExternalEvents(preferring: Set(["player", "*"]), allowing: Set(["player", "*"]))
|
||||||
@ -184,8 +183,6 @@ struct YatteeApp: App {
|
|||||||
InstancesManifest.shared.setPublicAccount(countryOfPublicInstances!, accounts: accounts, asCurrent: accounts.current.isNil)
|
InstancesManifest.shared.setPublicAccount(countryOfPublicInstances!, accounts: accounts, asCurrent: accounts.current.isNil)
|
||||||
}
|
}
|
||||||
|
|
||||||
PlayerModel.shared = player
|
|
||||||
|
|
||||||
playlists.accounts = accounts
|
playlists.accounts = accounts
|
||||||
search.accounts = accounts
|
search.accounts = accounts
|
||||||
subscriptions.accounts = accounts
|
subscriptions.accounts = accounts
|
||||||
@ -196,15 +193,11 @@ struct YatteeApp: App {
|
|||||||
menu.navigation = navigation
|
menu.navigation = navigation
|
||||||
menu.player = player
|
menu.player = player
|
||||||
|
|
||||||
playerControls.player = player
|
|
||||||
|
|
||||||
player.accounts = accounts
|
player.accounts = accounts
|
||||||
player.comments = comments
|
player.comments = comments
|
||||||
player.controls = playerControls
|
|
||||||
player.navigation = navigation
|
player.navigation = navigation
|
||||||
player.networkState = networkState
|
|
||||||
player.seek = .shared
|
|
||||||
|
|
||||||
|
PlayerModel.shared = player
|
||||||
PlayerTimeModel.shared.player = player
|
PlayerTimeModel.shared.player = player
|
||||||
|
|
||||||
if !accounts.current.isNil {
|
if !accounts.current.isNil {
|
||||||
|
@ -810,6 +810,9 @@
|
|||||||
37EF9A77275BEB8E0043B585 /* CommentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37EF9A75275BEB8E0043B585 /* CommentView.swift */; };
|
37EF9A77275BEB8E0043B585 /* CommentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37EF9A75275BEB8E0043B585 /* CommentView.swift */; };
|
||||||
37EF9A78275BEB8E0043B585 /* CommentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37EF9A75275BEB8E0043B585 /* CommentView.swift */; };
|
37EF9A78275BEB8E0043B585 /* CommentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37EF9A75275BEB8E0043B585 /* CommentView.swift */; };
|
||||||
37EF9A79275BEB8E0043B585 /* CommentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37EF9A75275BEB8E0043B585 /* CommentView.swift */; };
|
37EF9A79275BEB8E0043B585 /* CommentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37EF9A75275BEB8E0043B585 /* CommentView.swift */; };
|
||||||
|
37EFAC0828C138CD00ED9B89 /* ControlsOverlayModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37EFAC0728C138CD00ED9B89 /* ControlsOverlayModel.swift */; };
|
||||||
|
37EFAC0928C138CD00ED9B89 /* ControlsOverlayModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37EFAC0728C138CD00ED9B89 /* ControlsOverlayModel.swift */; };
|
||||||
|
37EFAC0A28C138CD00ED9B89 /* ControlsOverlayModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37EFAC0728C138CD00ED9B89 /* ControlsOverlayModel.swift */; };
|
||||||
37F0F4EA286F397E00C06C2E /* SettingsModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37F0F4E9286F397E00C06C2E /* SettingsModel.swift */; };
|
37F0F4EA286F397E00C06C2E /* SettingsModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37F0F4E9286F397E00C06C2E /* SettingsModel.swift */; };
|
||||||
37F0F4EB286F397E00C06C2E /* SettingsModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37F0F4E9286F397E00C06C2E /* SettingsModel.swift */; };
|
37F0F4EB286F397E00C06C2E /* SettingsModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37F0F4E9286F397E00C06C2E /* SettingsModel.swift */; };
|
||||||
37F0F4EC286F397E00C06C2E /* SettingsModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37F0F4E9286F397E00C06C2E /* SettingsModel.swift */; };
|
37F0F4EC286F397E00C06C2E /* SettingsModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37F0F4E9286F397E00C06C2E /* SettingsModel.swift */; };
|
||||||
@ -1284,6 +1287,7 @@
|
|||||||
37ECED55289FE166002BC2C9 /* SafeArea.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SafeArea.swift; sourceTree = "<group>"; };
|
37ECED55289FE166002BC2C9 /* SafeArea.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SafeArea.swift; sourceTree = "<group>"; };
|
||||||
37EF5C212739D37B00B03725 /* MenuModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MenuModel.swift; sourceTree = "<group>"; };
|
37EF5C212739D37B00B03725 /* MenuModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MenuModel.swift; sourceTree = "<group>"; };
|
||||||
37EF9A75275BEB8E0043B585 /* CommentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommentView.swift; sourceTree = "<group>"; };
|
37EF9A75275BEB8E0043B585 /* CommentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommentView.swift; sourceTree = "<group>"; };
|
||||||
|
37EFAC0728C138CD00ED9B89 /* ControlsOverlayModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ControlsOverlayModel.swift; sourceTree = "<group>"; };
|
||||||
37F0F4E9286F397E00C06C2E /* SettingsModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsModel.swift; sourceTree = "<group>"; };
|
37F0F4E9286F397E00C06C2E /* SettingsModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsModel.swift; sourceTree = "<group>"; };
|
||||||
37F0F4ED286F734400C06C2E /* AdvancedSettings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdvancedSettings.swift; sourceTree = "<group>"; };
|
37F0F4ED286F734400C06C2E /* AdvancedSettings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdvancedSettings.swift; sourceTree = "<group>"; };
|
||||||
37F13B61285E43C000B137E4 /* ControlsOverlay.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ControlsOverlay.swift; sourceTree = "<group>"; };
|
37F13B61285E43C000B137E4 /* ControlsOverlay.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ControlsOverlay.swift; sourceTree = "<group>"; };
|
||||||
@ -1723,6 +1727,7 @@
|
|||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
37EBD8C227AF0D7C00F1C24B /* Backends */,
|
37EBD8C227AF0D7C00F1C24B /* Backends */,
|
||||||
|
37EFAC0728C138CD00ED9B89 /* ControlsOverlayModel.swift */,
|
||||||
373031F428383A89000CFD59 /* PiPDelegate.swift */,
|
373031F428383A89000CFD59 /* PiPDelegate.swift */,
|
||||||
37B767DA2677C3CA0098BAA8 /* PlayerModel.swift */,
|
37B767DA2677C3CA0098BAA8 /* PlayerModel.swift */,
|
||||||
37319F0427103F94004ECCD0 /* PlayerQueue.swift */,
|
37319F0427103F94004ECCD0 /* PlayerQueue.swift */,
|
||||||
@ -2885,6 +2890,7 @@
|
|||||||
376BE50927347B5F009AD608 /* SettingsHeader.swift in Sources */,
|
376BE50927347B5F009AD608 /* SettingsHeader.swift in Sources */,
|
||||||
376527BB285F60F700102284 /* PlayerTimeModel.swift in Sources */,
|
376527BB285F60F700102284 /* PlayerTimeModel.swift in Sources */,
|
||||||
3722AEBE274DA401005EA4D6 /* Backport.swift in Sources */,
|
3722AEBE274DA401005EA4D6 /* Backport.swift in Sources */,
|
||||||
|
37EFAC0828C138CD00ED9B89 /* ControlsOverlayModel.swift in Sources */,
|
||||||
37F4AD2628613B81004D0F66 /* Color+Debug.swift in Sources */,
|
37F4AD2628613B81004D0F66 /* Color+Debug.swift in Sources */,
|
||||||
3700155F271B12DD0049C794 /* SiestaConfiguration.swift in Sources */,
|
3700155F271B12DD0049C794 /* SiestaConfiguration.swift in Sources */,
|
||||||
37F13B62285E43C000B137E4 /* ControlsOverlay.swift in Sources */,
|
37F13B62285E43C000B137E4 /* ControlsOverlay.swift in Sources */,
|
||||||
@ -3142,6 +3148,7 @@
|
|||||||
372915E72687E3B900F5A35B /* Defaults.swift in Sources */,
|
372915E72687E3B900F5A35B /* Defaults.swift in Sources */,
|
||||||
37C3A242272359900087A57A /* Double+Format.swift in Sources */,
|
37C3A242272359900087A57A /* Double+Format.swift in Sources */,
|
||||||
37B795912771DAE0001CF27B /* OpenURLHandler.swift in Sources */,
|
37B795912771DAE0001CF27B /* OpenURLHandler.swift in Sources */,
|
||||||
|
37EFAC0928C138CD00ED9B89 /* ControlsOverlayModel.swift in Sources */,
|
||||||
37DD87C8271C9CFE0027CBF9 /* PlayerStreams.swift in Sources */,
|
37DD87C8271C9CFE0027CBF9 /* PlayerStreams.swift in Sources */,
|
||||||
376578922685490700D4EA09 /* PlaylistsView.swift in Sources */,
|
376578922685490700D4EA09 /* PlaylistsView.swift in Sources */,
|
||||||
37F9619C27BD89E000058149 /* TapRecognizerViewModifier.swift in Sources */,
|
37F9619C27BD89E000058149 /* TapRecognizerViewModifier.swift in Sources */,
|
||||||
@ -3307,6 +3314,7 @@
|
|||||||
37DD9DBC2785D60300539416 /* FramePreferenceKey.swift in Sources */,
|
37DD9DBC2785D60300539416 /* FramePreferenceKey.swift in Sources */,
|
||||||
375EC974289F2ABF00751258 /* MultiselectRow.swift in Sources */,
|
375EC974289F2ABF00751258 /* MultiselectRow.swift in Sources */,
|
||||||
37EBD8C827AF26B300F1C24B /* AVPlayerBackend.swift in Sources */,
|
37EBD8C827AF26B300F1C24B /* AVPlayerBackend.swift in Sources */,
|
||||||
|
37EFAC0A28C138CD00ED9B89 /* ControlsOverlayModel.swift in Sources */,
|
||||||
37CC3F52270D010D00608308 /* VideoBanner.swift in Sources */,
|
37CC3F52270D010D00608308 /* VideoBanner.swift in Sources */,
|
||||||
37F49BA526CAA59B00304AC0 /* Playlist+Fixtures.swift in Sources */,
|
37F49BA526CAA59B00304AC0 /* Playlist+Fixtures.swift in Sources */,
|
||||||
376CD21826FBE18D001E1AC1 /* Instance+Fixtures.swift in Sources */,
|
376CD21826FBE18D001E1AC1 /* Instance+Fixtures.swift in Sources */,
|
||||||
|
Loading…
Reference in New Issue
Block a user