mirror of
https://github.com/yattee/yattee.git
synced 2024-12-22 21:43:41 +00:00
Fix tvOS streams selection
This commit is contained in:
parent
ec395ff2e0
commit
00d706766c
@ -22,8 +22,8 @@ final class PlayerModel: ObservableObject {
|
||||
@Published var stream: Stream?
|
||||
@Published var currentRate: Float?
|
||||
|
||||
@Published var availableStreams = [Stream]()
|
||||
@Published var streamSelection: Stream?
|
||||
@Published var availableStreams = [Stream]() { didSet { rebuildStreamsMenu() } }
|
||||
@Published var streamSelection: Stream? { didSet { rebuildStreamsMenu() } }
|
||||
|
||||
@Published var queue = [PlayerQueueItem]()
|
||||
@Published var currentItem: PlayerQueueItem!
|
||||
|
@ -1,5 +1,6 @@
|
||||
import Foundation
|
||||
import Siesta
|
||||
import SwiftUI
|
||||
|
||||
extension PlayerModel {
|
||||
var isLoadingAvailableStreams: Bool {
|
||||
@ -85,12 +86,47 @@ extension PlayerModel {
|
||||
completionHandler: @escaping ([Stream]) -> Void
|
||||
) {
|
||||
instancesWithLoadedStreams.append(instance)
|
||||
rebuildStreamsMenu()
|
||||
|
||||
if instances.all.count == instancesWithLoadedStreams.count {
|
||||
completionHandler(streams.sorted { $0.kind < $1.kind })
|
||||
}
|
||||
}
|
||||
|
||||
#if os(tvOS)
|
||||
var streamsMenu: UIMenu {
|
||||
UIMenu(
|
||||
title: "Streams",
|
||||
image: UIImage(systemName: "antenna.radiowaves.left.and.right"),
|
||||
children: streamsMenuActions
|
||||
)
|
||||
}
|
||||
|
||||
var streamsMenuActions: [UIAction] {
|
||||
guard !availableStreams.isEmpty else {
|
||||
return [ // swiftlint:disable:this implicit_return
|
||||
UIAction(title: "Empty", attributes: .disabled) { _ in }
|
||||
]
|
||||
}
|
||||
|
||||
return availableStreamsSorted.map { stream in
|
||||
let state = stream == streamSelection ? UIAction.State.on : .off
|
||||
|
||||
return UIAction(title: stream.description, state: state) { _ in
|
||||
self.streamSelection = stream
|
||||
self.upgradeToStream(stream)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
func rebuildStreamsMenu() {
|
||||
#if os(tvOS)
|
||||
avPlayerViewController?.transportBarCustomMenuItems = [streamsMenu]
|
||||
#endif
|
||||
}
|
||||
|
||||
func streamsWithInstance(instance: Instance, streams: [Stream]) -> [Stream] {
|
||||
streams.map { stream in
|
||||
stream.instance = instance
|
||||
|
@ -1032,7 +1032,7 @@
|
||||
attributes = {
|
||||
BuildIndependentTargetsInParallel = 1;
|
||||
LastSwiftUpdateCheck = 1300;
|
||||
LastUpgradeCheck = 1300;
|
||||
LastUpgradeCheck = 1310;
|
||||
TargetAttributes = {
|
||||
37BA796226DC40CB002A0235 = {
|
||||
CreatedOnToolsVersion = 13.0;
|
||||
@ -1832,6 +1832,7 @@
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
|
||||
CODE_SIGN_ENTITLEMENTS = Shared/Pearvidious.entitlements;
|
||||
CODE_SIGN_IDENTITY = "-";
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
COMBINE_HIDPI_IMAGES = YES;
|
||||
CURRENT_PROJECT_VERSION = 1;
|
||||
@ -1863,6 +1864,7 @@
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
|
||||
CODE_SIGN_ENTITLEMENTS = Shared/Pearvidious.entitlements;
|
||||
CODE_SIGN_IDENTITY = "-";
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
COMBINE_HIDPI_IMAGES = YES;
|
||||
CURRENT_PROJECT_VERSION = 1;
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "1300"
|
||||
LastUpgradeVersion = "1310"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "1300"
|
||||
LastUpgradeVersion = "1310"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "1300"
|
||||
LastUpgradeVersion = "1310"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "1300"
|
||||
LastUpgradeVersion = "1310"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
|
@ -20,43 +20,8 @@ struct Player: UIViewControllerRepresentable {
|
||||
controller.playerModel = player
|
||||
player.controller = controller
|
||||
|
||||
#if os(tvOS)
|
||||
player.controller?.playerViewController.transportBarCustomMenuItems = [streamingQualityMenu]
|
||||
#endif
|
||||
|
||||
return controller
|
||||
}
|
||||
|
||||
func updateUIViewController(_: PlayerViewController, context _: Context) {
|
||||
#if os(tvOS)
|
||||
player.controller?.playerViewController.transportBarCustomMenuItems = [streamingQualityMenu]
|
||||
#endif
|
||||
}
|
||||
|
||||
#if os(tvOS)
|
||||
var streamingQualityMenu: UIMenu {
|
||||
UIMenu(
|
||||
title: "Streams",
|
||||
image: UIImage(systemName: "antenna.radiowaves.left.and.right"),
|
||||
children: streamingQualityMenuActions
|
||||
)
|
||||
}
|
||||
|
||||
var streamingQualityMenuActions: [UIAction] {
|
||||
guard !player.availableStreams.isEmpty else {
|
||||
return [ // swiftlint:disable:this implicit_return
|
||||
UIAction(title: "Empty", attributes: .disabled) { _ in }
|
||||
]
|
||||
}
|
||||
|
||||
return player.availableStreamsSorted.map { stream in
|
||||
let state = player.streamSelection == stream ? UIAction.State.on : .off
|
||||
|
||||
return UIAction(title: stream.description, state: state) { _ in
|
||||
self.player.streamSelection = stream
|
||||
self.player.upgradeToStream(stream)
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
func updateUIViewController(_: PlayerViewController, context _: Context) {}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user