From 34990201dc06df79996eecb0442183ad55857818 Mon Sep 17 00:00:00 2001 From: Arkadiusz Fal Date: Sat, 28 May 2022 01:23:50 +0200 Subject: [PATCH] More controls improvements --- Model/Player/PlayerControlsModel.swift | 2 +- Shared/Player/Controls/PlayerControls.swift | 37 +++++++++++++-------- Shared/Player/TimelineView.swift | 3 +- Shared/Player/VideoPlayerView.swift | 19 ++++++----- 4 files changed, 36 insertions(+), 25 deletions(-) diff --git a/Model/Player/PlayerControlsModel.swift b/Model/Player/PlayerControlsModel.swift index 86434b1f..9025b5cd 100644 --- a/Model/Player/PlayerControlsModel.swift +++ b/Model/Player/PlayerControlsModel.swift @@ -43,7 +43,7 @@ final class PlayerControlsModel: ObservableObject { func handlePresentationChange() { if presentingControls { DispatchQueue.main.async { [weak self] in - self?.player.backend.startControlsUpdates() + self?.player?.backend.startControlsUpdates() self?.resetTimer() } } else { diff --git a/Shared/Player/Controls/PlayerControls.swift b/Shared/Player/Controls/PlayerControls.swift index 21ca3ad2..ea79bf40 100644 --- a/Shared/Player/Controls/PlayerControls.swift +++ b/Shared/Player/Controls/PlayerControls.swift @@ -58,14 +58,17 @@ struct PlayerControls: View { .offset(y: 10) .zIndex(1) - bottomBar + HStack { + Spacer() - #if os(macOS) - .background(VisualEffectBlur(material: .hudWindow)) - #elseif os(iOS) - .background(VisualEffectBlur(blurStyle: .systemThinMaterial)) - #endif - .mask(RoundedRectangle(cornerRadius: 3)) + bottomBar + #if os(macOS) + .background(VisualEffectBlur(material: .hudWindow)) + #elseif os(iOS) + .background(VisualEffectBlur(blurStyle: .systemThinMaterial)) + #endif + .mask(RoundedRectangle(cornerRadius: 3)) + } } .padding(.horizontal, 16) } @@ -171,7 +174,9 @@ struct PlayerControls: View { var buttonsBar: some View { HStack(spacing: 20) { #if !os(tvOS) - hidePlayerButton + #if os(iOS) + hidePlayerButton + #endif fullscreenButton #if os(iOS) @@ -235,7 +240,11 @@ struct PlayerControls: View { player.hide() player.closePiP() - DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) { + var delay = 0.3 + #if os(macOS) + delay = 0.0 + #endif + DispatchQueue.main.asyncAfter(deadline: .now() + delay) { player.closeCurrentItem() } } @@ -260,7 +269,9 @@ struct PlayerControls: View { player.avPlayerBackend.switchToMPVOnPipClose = true } - player.exitFullScreen() + #if !os(macOS) + player.exitFullScreen() + #endif if player.activeBackend != PlayerBackendType.appleAVPlayer { player.saveTime { @@ -329,8 +340,6 @@ struct PlayerControls: View { var bottomBar: some View { HStack { - Spacer() - Text(model.playbackTime) } .font(.system(size: 15)) @@ -384,7 +393,7 @@ struct PlayerControls_Previews: PreviewProvider { model.duration = .secondsInDefaultTimescale(120) let view = ZStack { - Color.red + Color.gray PlayerControls(player: PlayerModel()) .injectFixtureEnvironmentObjects() @@ -392,7 +401,7 @@ struct PlayerControls_Previews: PreviewProvider { } return Group { - if #available(iOS 15.0, *) { + if #available(iOS 15.0, macOS 12.0, tvOS 15.0, *) { view.previewInterfaceOrientation(.landscapeLeft) } else { view diff --git a/Shared/Player/TimelineView.swift b/Shared/Player/TimelineView.swift index 61e127df..98758aa0 100644 --- a/Shared/Player/TimelineView.swift +++ b/Shared/Player/TimelineView.swift @@ -38,7 +38,6 @@ struct TimelineView: View { segmentsLayers } - .mask(RoundedRectangle(cornerRadius: 3)) Circle() .strokeBorder(.gray, lineWidth: 1) @@ -114,7 +113,7 @@ struct TimelineView: View { var projectedValue: Double { let change = (dragOffset / size.width) * units let projected = draggedFrom + change - return projected.isFinite ? (duration - projected < (0.03 * duration) ? duration : projected) : start + return projected.isFinite ? (duration - projected < (0.01 * duration) ? duration : projected) : start } var thumbOffset: Double { diff --git a/Shared/Player/VideoPlayerView.swift b/Shared/Player/VideoPlayerView.swift index cb61f0d5..e71a28d3 100644 --- a/Shared/Player/VideoPlayerView.swift +++ b/Shared/Player/VideoPlayerView.swift @@ -276,14 +276,17 @@ struct VideoPlayerView: View { Spacer() } - Button { - player.hide() - } label: { - Image(systemName: "xmark") - .font(.system(size: 40)) - } - .padding(10) - .foregroundColor(.gray) + #if os(iOS) + Button { + player.hide() + } label: { + Image(systemName: "xmark") + .font(.system(size: 40)) + } + .buttonStyle(.plain) + .padding(10) + .foregroundColor(.gray) + #endif } .contentShape(Rectangle()) .frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: geometry.size.width / Self.defaultAspectRatio)