yattee/Shared/Player/AppleAVPlayerView.swift

46 lines
1.6 KiB
Swift
Raw Normal View History

2022-05-20 21:23:14 +00:00
import AVKit
2021-09-25 08:18:22 +00:00
import Defaults
2021-07-18 22:32:46 +00:00
import SwiftUI
2022-08-20 21:05:40 +00:00
#if os(iOS)
struct AppleAVPlayerView: UIViewRepresentable {
@EnvironmentObject<PlayerModel> private var player
2021-08-23 21:31:51 +00:00
2022-08-20 21:05:40 +00:00
func makeUIView(context _: Context) -> some UIView {
let playerLayerView = PlayerLayerView(frame: .zero)
playerLayerView.player = player
return playerLayerView
}
func updateUIView(_: UIViewType, context _: Context) {}
2021-07-18 22:32:46 +00:00
}
2022-08-20 21:05:40 +00:00
#else
struct AppleAVPlayerView: UIViewControllerRepresentable {
@EnvironmentObject<AccountsModel> private var accounts
@EnvironmentObject<CommentsModel> private var comments
@EnvironmentObject<NavigationModel> private var navigation
@EnvironmentObject<PlayerModel> private var player
@EnvironmentObject<PlaylistsModel> private var playlists
@EnvironmentObject<SubscriptionsModel> private var subscriptions
func makeUIViewController(context _: Context) -> AppleAVPlayerViewController {
let controller = AppleAVPlayerViewController()
controller.accountsModel = accounts
controller.commentsModel = comments
controller.navigationModel = navigation
controller.playerModel = player
controller.playlistsModel = playlists
controller.subscriptionsModel = subscriptions
2021-07-18 22:32:46 +00:00
2022-08-20 21:05:40 +00:00
player.avPlayerBackend.controller = controller
return controller
}
func updateUIViewController(_: AppleAVPlayerViewController, context _: Context) {
player.rebuildTVMenu()
}
}
#endif