diff --git a/Packages/Models/Sources/Models/MediaAttachement.swift b/Packages/Models/Sources/Models/MediaAttachement.swift index 613107b2..3f7375bc 100644 --- a/Packages/Models/Sources/Models/MediaAttachement.swift +++ b/Packages/Models/Sources/Models/MediaAttachement.swift @@ -1,15 +1,6 @@ import Foundation -public struct MediaAttachement: Codable, Identifiable, Hashable { - public struct Meta: Codable, Equatable { - public let width: Int? - public let height: Int? - public let size: String? - public let aspect: Float? - public let x: Float? - public let y: Float? - } - +public struct MediaAttachement: Codable, Identifiable, Hashable { public enum SupportedType: String { case image, gifv } @@ -26,6 +17,5 @@ public struct MediaAttachement: Codable, Identifiable, Hashable { public let url: URL public let previewUrl: URL? public let description: String? - public let meta: [String: Meta]? } diff --git a/Packages/Status/Sources/Status/Row/StatusMediaPreviewView.swift b/Packages/Status/Sources/Status/Row/StatusMediaPreviewView.swift index 76459c21..f04e0059 100644 --- a/Packages/Status/Sources/Status/Row/StatusMediaPreviewView.swift +++ b/Packages/Status/Sources/Status/Row/StatusMediaPreviewView.swift @@ -2,8 +2,33 @@ import SwiftUI import Models import AVKit +private class VideoPlayerViewModel: ObservableObject { + @Published var player: AVPlayer? + private let url: URL + + init(url: URL) { + self.url = url + } + + func preparePlayer() { + player = .init(url: url) + player?.play() + } +} + +private struct VideoPlayerView: View { + @StateObject var viewModel: VideoPlayerViewModel + var body: some View { + VStack { + VideoPlayer(player: viewModel.player) + }.onAppear { + viewModel.preparePlayer() + } + } +} + // Could have just been a state, but SwiftUI .sheet is buggy ATM without @StateObject -class SelectedMediaSheetManager: ObservableObject { +private class SelectedMediaSheetManager: ObservableObject { @Published var selectedAttachement: MediaAttachement? } @@ -58,7 +83,7 @@ public struct StatusMediaPreviewView: View { } ) case .gifv: - VideoPlayer(player: AVPlayer(url: attachement.url)) + VideoPlayerView(viewModel: .init(url: attachement.url)) .frame(width: proxy.frame(in: .local).width) .frame(height: attachements.count > 2 ? 100 : 200) } @@ -98,7 +123,7 @@ public struct StatusMediaPreviewView: View { } ) case .gifv: - VideoPlayer(player: AVPlayer(url: attachement.url)) + VideoPlayerView(viewModel: .init(url: attachement.url)) } Spacer() }