use coordinator to show player

This commit is contained in:
jhays 2021-11-18 21:06:04 -06:00
parent 7dab722cda
commit 43cd1ecc62
4 changed files with 14 additions and 4 deletions

View File

@ -10,14 +10,16 @@
import SwiftUI
struct MediaPlayButtonRowView: View {
@EnvironmentObject var itemRouter: ItemCoordinator.Router
@ObservedObject var viewModel: ItemViewModel
@State var wrappedScrollView: UIScrollView?
var body: some View {
HStack {
VStack {
NavigationLink(destination: VideoPlayerView(item: viewModel.item).ignoresSafeArea()) {
Button {
self.itemRouter.route(to: \.videoPlayer, viewModel.item)
} label: {
MediaViewActionButton(icon: "play.fill", scrollView: $wrappedScrollView)
}
Text(viewModel.item.getItemProgressString() != "" ? "\(viewModel.item.getItemProgressString()) left" : L10n.play)

View File

@ -7,17 +7,23 @@
* Copyright 2021 Aiden Vigue & Jellyfin Contributors
*/
import Stinsen
import SwiftUI
import JellyfinAPI
struct VideoPlayerView: UIViewControllerRepresentable {
var item: BaseItemDto
@EnvironmentObject var router: VideoPlayerCoordinator.Router
var item: BaseItemDto
func makeUIViewController(context: Context) -> some UIViewController {
let storyboard = UIStoryboard(name: "VideoPlayer", bundle: nil)
let viewController = storyboard.instantiateViewController(withIdentifier: "VideoPlayer") as! VideoPlayerViewController
viewController.manifest = item
viewController.backAction = {
self.router.dismissCoordinator()
}
return viewController
}

View File

@ -65,6 +65,7 @@ class VideoPlayerViewController: UIViewController, VideoPlayerSettingsDelegate,
var manifest: BaseItemDto = BaseItemDto()
var playbackItem = PlaybackItem()
var playSessionId: String = ""
var backAction = {}
var cancellables = Set<AnyCancellable>()
@ -486,7 +487,7 @@ class VideoPlayerViewController: UIViewController, VideoPlayerSettingsDelegate,
self.resignFirstResponder()
mediaPlayer.stop()
sendStopReport()
self.navigationController?.popViewController(animated: true)
backAction()
}
}

View File

@ -26,5 +26,6 @@ final class VideoPlayerCoordinator: NavigationCoordinatable {
@ViewBuilder func makeStart() -> some View {
VideoPlayerView(item: item)
.ignoresSafeArea()
}
}