From d3336b3ae142455068963f0a28874ecd4e514a47 Mon Sep 17 00:00:00 2001 From: Arkadiusz Fal Date: Mon, 11 Jul 2022 18:21:03 +0200 Subject: [PATCH] Aspect ratio fixes --- Model/Player/Backends/AVPlayerBackend.swift | 2 +- Model/Player/Backends/MPVBackend.swift | 3 +-- Model/Player/Backends/PlayerBackend.swift | 6 ++++++ Shared/Player/VideoPlayerView.swift | 13 ++++--------- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Model/Player/Backends/AVPlayerBackend.swift b/Model/Player/Backends/AVPlayerBackend.swift index 9b71a9af..ad3e7200 100644 --- a/Model/Player/Backends/AVPlayerBackend.swift +++ b/Model/Player/Backends/AVPlayerBackend.swift @@ -318,7 +318,7 @@ final class AVPlayerBackend: PlayerBackend { return } - self.model.aspectRatio = self.aspectRatio + self.updatePlayerAspectRatio() if !preservingTime, let segment = self.model.sponsorBlock.segments.first, diff --git a/Model/Player/Backends/MPVBackend.swift b/Model/Player/Backends/MPVBackend.swift index 2c264ffa..38279725 100644 --- a/Model/Player/Backends/MPVBackend.swift +++ b/Model/Player/Backends/MPVBackend.swift @@ -45,6 +45,7 @@ final class MPVBackend: PlayerBackend { networkStateTimer.start() if isPlaying { + self.updatePlayerAspectRatio() startClientUpdates() } else { stopControlsUpdates() @@ -204,11 +205,9 @@ final class MPVBackend: PlayerBackend { self.model.lastSkipped = segment self.play() - self.model.aspectRatio = self.aspectRatio } } else { self.play() - self.model.aspectRatio = self.aspectRatio } } } diff --git a/Model/Player/Backends/PlayerBackend.swift b/Model/Player/Backends/PlayerBackend.swift index 3b2a4179..ee7d1b1b 100644 --- a/Model/Player/Backends/PlayerBackend.swift +++ b/Model/Player/Backends/PlayerBackend.swift @@ -98,4 +98,10 @@ extension PlayerBackend { model.advanceToItem(item) } } + + func updatePlayerAspectRatio() { + DispatchQueue.main.async { + self.model.aspectRatio = aspectRatio + } + } } diff --git a/Shared/Player/VideoPlayerView.swift b/Shared/Player/VideoPlayerView.swift index 4dff939a..f1c3e0e8 100644 --- a/Shared/Player/VideoPlayerView.swift +++ b/Shared/Player/VideoPlayerView.swift @@ -300,15 +300,10 @@ struct VideoPlayerView: View { } .overlay(GeometryReader { proxy in Color.clear - .onAppear { - player.playerSize = proxy.size - } - .onChange(of: proxy.size) { _ in - player.playerSize = proxy.size - } - .onChange(of: player.controls.presentingOverlays) { _ in - player.playerSize = proxy.size - } + .onAppear { player.playerSize = proxy.size } + .onChange(of: proxy.size) { _ in player.playerSize = proxy.size } + .onChange(of: player.controls.presentingOverlays) { _ in player.playerSize = proxy.size } + .onChange(of: player.aspectRatio) { _ in player.playerSize = proxy.size } }) #if os(iOS) .padding(.top, player.playingFullScreen && verticalSizeClass == .regular ? 20 : 0)