mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2025-01-05 05:48:50 +00:00
Fix video player
This commit is contained in:
parent
cff6f3a843
commit
6144e2ba6a
2 changed files with 29 additions and 14 deletions
|
@ -1,15 +1,6 @@
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
public struct MediaAttachement: Codable, Identifiable, Hashable {
|
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 enum SupportedType: String {
|
public enum SupportedType: String {
|
||||||
case image, gifv
|
case image, gifv
|
||||||
}
|
}
|
||||||
|
@ -26,6 +17,5 @@ public struct MediaAttachement: Codable, Identifiable, Hashable {
|
||||||
public let url: URL
|
public let url: URL
|
||||||
public let previewUrl: URL?
|
public let previewUrl: URL?
|
||||||
public let description: String?
|
public let description: String?
|
||||||
public let meta: [String: Meta]?
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,8 +2,33 @@ import SwiftUI
|
||||||
import Models
|
import Models
|
||||||
import AVKit
|
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
|
// 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?
|
@Published var selectedAttachement: MediaAttachement?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,7 +83,7 @@ public struct StatusMediaPreviewView: View {
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
case .gifv:
|
case .gifv:
|
||||||
VideoPlayer(player: AVPlayer(url: attachement.url))
|
VideoPlayerView(viewModel: .init(url: attachement.url))
|
||||||
.frame(width: proxy.frame(in: .local).width)
|
.frame(width: proxy.frame(in: .local).width)
|
||||||
.frame(height: attachements.count > 2 ? 100 : 200)
|
.frame(height: attachements.count > 2 ? 100 : 200)
|
||||||
}
|
}
|
||||||
|
@ -98,7 +123,7 @@ public struct StatusMediaPreviewView: View {
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
case .gifv:
|
case .gifv:
|
||||||
VideoPlayer(player: AVPlayer(url: attachement.url))
|
VideoPlayerView(viewModel: .init(url: attachement.url))
|
||||||
}
|
}
|
||||||
Spacer()
|
Spacer()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue