96 lines
3.8 KiB
Swift
96 lines
3.8 KiB
Swift
/* JellyfinPlayer/Swiftfin is subject to the terms of the Mozilla Public
|
|
* License, v2.0. If a copy of the MPL was not distributed with this
|
|
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
|
|
*
|
|
* Copyright 2021 Aiden Vigue & Jellyfin Contributors
|
|
*/
|
|
|
|
import SwiftUI
|
|
import Introspect
|
|
import JellyfinAPI
|
|
|
|
//good lord the environmental modifiers ;P
|
|
|
|
class VideoPlayerItem: ObservableObject {
|
|
@Published var shouldShowPlayer: Bool = false;
|
|
@Published var itemToPlay: BaseItemDto = BaseItemDto();
|
|
}
|
|
|
|
struct ItemView: View {
|
|
@EnvironmentObject private var globalData: GlobalData
|
|
|
|
@State private var fullItem: BaseItemDto = BaseItemDto();
|
|
private var item: BaseItemDto;
|
|
|
|
@StateObject private var videoPlayerItem: VideoPlayerItem = VideoPlayerItem()
|
|
@State private var videoIsLoading: Bool = false; //This variable is only changed by the underlying VLC view.
|
|
@State private var isLoading: Bool = false;
|
|
|
|
init(item: BaseItemDto) {
|
|
self.item = item
|
|
}
|
|
|
|
func onAppear() {
|
|
isLoading = true;
|
|
UserLibraryAPI.getItem(userId: globalData.user.user_id!, itemId: item.id!)
|
|
.sink(receiveCompletion: { completion in
|
|
HandleAPIRequestCompletion(globalData: globalData, completion: completion)
|
|
}, receiveValue: { response in
|
|
isLoading = false
|
|
fullItem = response
|
|
})
|
|
.store(in: &globalData.pendingAPIRequests)
|
|
}
|
|
|
|
var body: some View {
|
|
VStack {
|
|
if(videoPlayerItem.shouldShowPlayer) {
|
|
LoadingViewNoBlur(isShowing: $videoIsLoading) {
|
|
VLCPlayerWithControls(item: videoPlayerItem.itemToPlay, loadBinding: $videoIsLoading, pBinding: _videoPlayerItem.projectedValue.shouldShowPlayer)
|
|
}.navigationBarHidden(true)
|
|
.navigationBarBackButtonHidden(true)
|
|
.statusBar(hidden: true)
|
|
.prefersHomeIndicatorAutoHidden(true)
|
|
.preferredColorScheme(.dark)
|
|
.edgesIgnoringSafeArea(.all)
|
|
.overrideViewPreference(.unspecified)
|
|
.supportedOrientations(.landscape)
|
|
} else {
|
|
if(isLoading) {
|
|
ProgressView()
|
|
} else {
|
|
VStack {
|
|
if(fullItem.type == "Movie") {
|
|
MovieItemView(item: fullItem)
|
|
} else if(fullItem.type == "Season") {
|
|
EmptyView()
|
|
//SeasonItemView(item: fullItem)
|
|
} else if(fullItem.type == "Series") {
|
|
EmptyView()
|
|
//SeriesItemView(item: fullItem)
|
|
} else if(fullItem.type == "Episode") {
|
|
EmptyView()
|
|
//EpisodeItemView(item: fullItem)
|
|
} else {
|
|
Text("Type: \(fullItem.type ?? "") not implemented yet :(")
|
|
}
|
|
}
|
|
.introspectTabBarController { (UITabBarController) in
|
|
UITabBarController.tabBar.isHidden = false
|
|
}
|
|
.navigationBarHidden(false)
|
|
.navigationBarBackButtonHidden(false)
|
|
.statusBar(hidden: false)
|
|
.prefersHomeIndicatorAutoHidden(false)
|
|
.preferredColorScheme(.none)
|
|
.edgesIgnoringSafeArea([])
|
|
.overrideViewPreference(.unspecified)
|
|
.supportedOrientations(.allButUpsideDown)
|
|
.environmentObject(videoPlayerItem)
|
|
}
|
|
}
|
|
}
|
|
.onAppear(perform: onAppear)
|
|
}
|
|
}
|