Always autoplay video in the new media viewer
This commit is contained in:
parent
1743b3bc08
commit
8ed6d548eb
|
@ -8,16 +8,18 @@ import SwiftUI
|
|||
@Observable public class MediaUIAttachmentVideoViewModel {
|
||||
var player: AVPlayer?
|
||||
private let url: URL
|
||||
let forceAutoPlay: Bool
|
||||
|
||||
public init(url: URL) {
|
||||
public init(url: URL, forceAutoPlay: Bool = false) {
|
||||
self.url = url
|
||||
self.forceAutoPlay = forceAutoPlay
|
||||
}
|
||||
|
||||
func preparePlayer(autoPlay: Bool) {
|
||||
player = .init(url: url)
|
||||
player?.isMuted = true
|
||||
player?.audiovisualBackgroundPlaybackPolicy = .pauses
|
||||
if autoPlay {
|
||||
if autoPlay || forceAutoPlay {
|
||||
player?.play()
|
||||
} else {
|
||||
player?.pause()
|
||||
|
@ -27,7 +29,7 @@ import SwiftUI
|
|||
object: player.currentItem, queue: .main)
|
||||
{ _ in
|
||||
Task { @MainActor [weak self] in
|
||||
if autoPlay {
|
||||
if autoPlay || self?.forceAutoPlay == true {
|
||||
self?.play()
|
||||
}
|
||||
}
|
||||
|
@ -65,7 +67,7 @@ public struct MediaUIAttachmentVideoView: View {
|
|||
VideoPlayer(player: viewModel.player)
|
||||
.accessibilityAddTraits(.startsMediaSession)
|
||||
|
||||
if !preferences.autoPlayVideo {
|
||||
if !preferences.autoPlayVideo && !viewModel.forceAutoPlay {
|
||||
Image(systemName: "play.fill")
|
||||
.font(isCompact ? .body : .largeTitle)
|
||||
.foregroundColor(theme.tintColor)
|
||||
|
@ -85,7 +87,7 @@ public struct MediaUIAttachmentVideoView: View {
|
|||
case .background, .inactive:
|
||||
viewModel.pause()
|
||||
case .active:
|
||||
if preferences.autoPlayVideo {
|
||||
if preferences.autoPlayVideo || viewModel.forceAutoPlay {
|
||||
viewModel.play()
|
||||
}
|
||||
default:
|
||||
|
|
|
@ -33,7 +33,7 @@ public struct MediaUIView: View {
|
|||
.containerRelativeFrame(.horizontal, count: 1, span: 1, spacing: 0)
|
||||
.id(attachment.id)
|
||||
case .video, .gifv, .audio:
|
||||
MediaUIAttachmentVideoView(viewModel: .init(url: url))
|
||||
MediaUIAttachmentVideoView(viewModel: .init(url: url, forceAutoPlay: true))
|
||||
.containerRelativeFrame(.horizontal, count: 1, span: 1, spacing: 0)
|
||||
.containerRelativeFrame(.vertical, count: 1, span: 1, spacing: 0)
|
||||
.id(attachment.id)
|
||||
|
|
Loading…
Reference in New Issue