2021-06-10 22:50:10 +00:00
|
|
|
import AVKit
|
|
|
|
import Foundation
|
2021-06-28 10:43:07 +00:00
|
|
|
import Siesta
|
2021-06-10 22:50:10 +00:00
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct PlayerView: View {
|
2021-06-28 10:43:07 +00:00
|
|
|
@ObservedObject private var store = Store<Video>()
|
|
|
|
|
|
|
|
let resource: Resource
|
2021-06-11 00:05:59 +00:00
|
|
|
|
|
|
|
init(id: String) {
|
2021-06-28 10:43:07 +00:00
|
|
|
resource = InvidiousAPI.shared.video(id)
|
|
|
|
resource.addObserver(store)
|
2021-06-11 00:05:59 +00:00
|
|
|
}
|
2021-06-10 22:50:10 +00:00
|
|
|
|
|
|
|
var body: some View {
|
2021-06-16 19:12:41 +00:00
|
|
|
VStack {
|
|
|
|
pvc?
|
|
|
|
.edgesIgnoringSafeArea(.all)
|
2021-06-10 22:50:10 +00:00
|
|
|
}
|
2021-06-28 10:43:07 +00:00
|
|
|
.onAppear {
|
|
|
|
resource.loadIfNeeded()
|
2021-06-10 22:50:10 +00:00
|
|
|
}
|
|
|
|
}
|
2021-06-16 19:12:41 +00:00
|
|
|
|
|
|
|
var pvc: PlayerViewController? {
|
2021-06-28 10:43:07 +00:00
|
|
|
guard store.item != nil else {
|
2021-06-16 19:12:41 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-06-28 10:43:07 +00:00
|
|
|
return PlayerViewController(video: store.item!)
|
2021-06-16 19:12:41 +00:00
|
|
|
}
|
2021-06-10 22:50:10 +00:00
|
|
|
}
|