mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2024-11-26 10:11:00 +00:00
Cleanup
This commit is contained in:
parent
25a80eea65
commit
a90a63bf1b
2 changed files with 38 additions and 44 deletions
37
Packages/Status/Sources/Status/Media/VideoPlayerView.swift
Normal file
37
Packages/Status/Sources/Status/Media/VideoPlayerView.swift
Normal file
|
@ -0,0 +1,37 @@
|
|||
import SwiftUI
|
||||
import AVKit
|
||||
|
||||
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()
|
||||
guard let player else { return }
|
||||
NotificationCenter.default.addObserver(forName: .AVPlayerItemDidPlayToEndTime,
|
||||
object: player.currentItem, queue: .main) { [weak self] _ in
|
||||
self?.player?.seek(to: CMTime.zero)
|
||||
self?.player?.play()
|
||||
}
|
||||
}
|
||||
|
||||
deinit {
|
||||
NotificationCenter.default.removeObserver(self, name: .AVPlayerItemDidPlayToEndTime, object: self.player)
|
||||
}
|
||||
}
|
||||
|
||||
struct VideoPlayerView: View {
|
||||
@StateObject var viewModel: VideoPlayerViewModel
|
||||
var body: some View {
|
||||
VStack {
|
||||
VideoPlayer(player: viewModel.player)
|
||||
}.onAppear {
|
||||
viewModel.preparePlayer()
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,56 +1,13 @@
|
|||
import SwiftUI
|
||||
import Models
|
||||
import AVKit
|
||||
import Env
|
||||
import Shimmer
|
||||
|
||||
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()
|
||||
guard let player else { return }
|
||||
NotificationCenter.default.addObserver(forName: .AVPlayerItemDidPlayToEndTime,
|
||||
object: player.currentItem, queue: .main) { [weak self] _ in
|
||||
self?.player?.seek(to: CMTime.zero)
|
||||
self?.player?.play()
|
||||
}
|
||||
}
|
||||
|
||||
deinit {
|
||||
NotificationCenter.default.removeObserver(self, name: .AVPlayerItemDidPlayToEndTime, object: self.player)
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
private class SelectedMediaSheetManager: ObservableObject {
|
||||
@Published var selectedAttachement: MediaAttachement?
|
||||
}
|
||||
|
||||
public struct StatusMediaPreviewView: View {
|
||||
@EnvironmentObject private var quickLook: QuickLook
|
||||
|
||||
public let attachements: [MediaAttachement]
|
||||
|
||||
@StateObject private var selectedMediaSheetManager = SelectedMediaSheetManager()
|
||||
|
||||
@State private var isQuickLookLoading: Bool = false
|
||||
|
||||
private var imageMaxHeight: CGFloat {
|
||||
|
|
Loading…
Reference in a new issue