Don't autoplay in compact mode

This commit is contained in:
Thomas Ricouard 2024-01-07 16:32:36 +01:00
parent 5ca5dfbd24
commit d378341914

View file

@ -16,10 +16,10 @@ import SwiftUI
self.forceAutoPlay = forceAutoPlay self.forceAutoPlay = forceAutoPlay
} }
func preparePlayer(autoPlay: Bool) { func preparePlayer(autoPlay: Bool, isCompact: Bool) {
player = .init(url: url) player = .init(url: url)
player?.audiovisualBackgroundPlaybackPolicy = .pauses player?.audiovisualBackgroundPlaybackPolicy = .pauses
if autoPlay || forceAutoPlay { if (autoPlay || forceAutoPlay) && !isCompact {
player?.play() player?.play()
isPlaying = true isPlaying = true
} else { } else {
@ -72,7 +72,8 @@ public struct MediaUIAttachmentVideoView: View {
videoView videoView
.onAppear { .onAppear {
try? AVAudioSession.sharedInstance().setCategory(.playback) try? AVAudioSession.sharedInstance().setCategory(.playback)
viewModel.preparePlayer(autoPlay: isFullScreen ? true : preferences.autoPlayVideo) viewModel.preparePlayer(autoPlay: isFullScreen ? true : preferences.autoPlayVideo,
isCompact: isCompact)
} }
.onDisappear { .onDisappear {
try? AVAudioSession.sharedInstance().setCategory(.ambient) try? AVAudioSession.sharedInstance().setCategory(.ambient)
@ -99,7 +100,7 @@ public struct MediaUIAttachmentVideoView: View {
case .background, .inactive: case .background, .inactive:
viewModel.pause() viewModel.pause()
case .active: case .active:
if preferences.autoPlayVideo || viewModel.forceAutoPlay || isFullScreen { if (preferences.autoPlayVideo || viewModel.forceAutoPlay || isFullScreen) && !isCompact {
viewModel.play() viewModel.play()
} }
default: default: