Fix video player
This commit is contained in:
parent
cff6f3a843
commit
6144e2ba6a
|
@ -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]?
|
||||
}
|
||||
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue