From d378341914d8d3f497b2cf4aa8405f36f2217a0b Mon Sep 17 00:00:00 2001 From: Thomas Ricouard Date: Sun, 7 Jan 2024 16:32:36 +0100 Subject: [PATCH] Don't autoplay in compact mode --- .../Sources/MediaUI/MediaUIAttachmentVideoView.swift | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Packages/MediaUI/Sources/MediaUI/MediaUIAttachmentVideoView.swift b/Packages/MediaUI/Sources/MediaUI/MediaUIAttachmentVideoView.swift index 175a3cee..64e5e53b 100644 --- a/Packages/MediaUI/Sources/MediaUI/MediaUIAttachmentVideoView.swift +++ b/Packages/MediaUI/Sources/MediaUI/MediaUIAttachmentVideoView.swift @@ -16,10 +16,10 @@ import SwiftUI self.forceAutoPlay = forceAutoPlay } - func preparePlayer(autoPlay: Bool) { + func preparePlayer(autoPlay: Bool, isCompact: Bool) { player = .init(url: url) player?.audiovisualBackgroundPlaybackPolicy = .pauses - if autoPlay || forceAutoPlay { + if (autoPlay || forceAutoPlay) && !isCompact { player?.play() isPlaying = true } else { @@ -72,7 +72,8 @@ public struct MediaUIAttachmentVideoView: View { videoView .onAppear { try? AVAudioSession.sharedInstance().setCategory(.playback) - viewModel.preparePlayer(autoPlay: isFullScreen ? true : preferences.autoPlayVideo) + viewModel.preparePlayer(autoPlay: isFullScreen ? true : preferences.autoPlayVideo, + isCompact: isCompact) } .onDisappear { try? AVAudioSession.sharedInstance().setCategory(.ambient) @@ -99,7 +100,7 @@ public struct MediaUIAttachmentVideoView: View { case .background, .inactive: viewModel.pause() case .active: - if preferences.autoPlayVideo || viewModel.forceAutoPlay || isFullScreen { + if (preferences.autoPlayVideo || viewModel.forceAutoPlay || isFullScreen) && !isCompact { viewModel.play() } default: