mirror of
https://github.com/yattee/yattee.git
synced 2025-01-09 06:17:10 +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 stream: Stream?
|
||||||
@Published var currentRate: Float?
|
@Published var currentRate: Float?
|
||||||
|
|
||||||
@Published var availableStreams = [Stream]()
|
@Published var availableStreams = [Stream]() { didSet { rebuildStreamsMenu() } }
|
||||||
@Published var streamSelection: Stream?
|
@Published var streamSelection: Stream? { didSet { rebuildStreamsMenu() } }
|
||||||
|
|
||||||
@Published var queue = [PlayerQueueItem]()
|
@Published var queue = [PlayerQueueItem]()
|
||||||
@Published var currentItem: PlayerQueueItem!
|
@Published var currentItem: PlayerQueueItem!
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
import Siesta
|
import Siesta
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
extension PlayerModel {
|
extension PlayerModel {
|
||||||
var isLoadingAvailableStreams: Bool {
|
var isLoadingAvailableStreams: Bool {
|
||||||
@ -85,12 +86,47 @@ extension PlayerModel {
|
|||||||
completionHandler: @escaping ([Stream]) -> Void
|
completionHandler: @escaping ([Stream]) -> Void
|
||||||
) {
|
) {
|
||||||
instancesWithLoadedStreams.append(instance)
|
instancesWithLoadedStreams.append(instance)
|
||||||
|
rebuildStreamsMenu()
|
||||||
|
|
||||||
if instances.all.count == instancesWithLoadedStreams.count {
|
if instances.all.count == instancesWithLoadedStreams.count {
|
||||||
completionHandler(streams.sorted { $0.kind < $1.kind })
|
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] {
|
func streamsWithInstance(instance: Instance, streams: [Stream]) -> [Stream] {
|
||||||
streams.map { stream in
|
streams.map { stream in
|
||||||
stream.instance = instance
|
stream.instance = instance
|
||||||
|
@ -1032,7 +1032,7 @@
|
|||||||
attributes = {
|
attributes = {
|
||||||
BuildIndependentTargetsInParallel = 1;
|
BuildIndependentTargetsInParallel = 1;
|
||||||
LastSwiftUpdateCheck = 1300;
|
LastSwiftUpdateCheck = 1300;
|
||||||
LastUpgradeCheck = 1300;
|
LastUpgradeCheck = 1310;
|
||||||
TargetAttributes = {
|
TargetAttributes = {
|
||||||
37BA796226DC40CB002A0235 = {
|
37BA796226DC40CB002A0235 = {
|
||||||
CreatedOnToolsVersion = 13.0;
|
CreatedOnToolsVersion = 13.0;
|
||||||
@ -1832,6 +1832,7 @@
|
|||||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||||
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
|
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
|
||||||
CODE_SIGN_ENTITLEMENTS = Shared/Pearvidious.entitlements;
|
CODE_SIGN_ENTITLEMENTS = Shared/Pearvidious.entitlements;
|
||||||
|
CODE_SIGN_IDENTITY = "-";
|
||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
COMBINE_HIDPI_IMAGES = YES;
|
COMBINE_HIDPI_IMAGES = YES;
|
||||||
CURRENT_PROJECT_VERSION = 1;
|
CURRENT_PROJECT_VERSION = 1;
|
||||||
@ -1863,6 +1864,7 @@
|
|||||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||||
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
|
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
|
||||||
CODE_SIGN_ENTITLEMENTS = Shared/Pearvidious.entitlements;
|
CODE_SIGN_ENTITLEMENTS = Shared/Pearvidious.entitlements;
|
||||||
|
CODE_SIGN_IDENTITY = "-";
|
||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
COMBINE_HIDPI_IMAGES = YES;
|
COMBINE_HIDPI_IMAGES = YES;
|
||||||
CURRENT_PROJECT_VERSION = 1;
|
CURRENT_PROJECT_VERSION = 1;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<Scheme
|
<Scheme
|
||||||
LastUpgradeVersion = "1300"
|
LastUpgradeVersion = "1310"
|
||||||
version = "1.3">
|
version = "1.3">
|
||||||
<BuildAction
|
<BuildAction
|
||||||
parallelizeBuildables = "YES"
|
parallelizeBuildables = "YES"
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<Scheme
|
<Scheme
|
||||||
LastUpgradeVersion = "1300"
|
LastUpgradeVersion = "1310"
|
||||||
version = "1.3">
|
version = "1.3">
|
||||||
<BuildAction
|
<BuildAction
|
||||||
parallelizeBuildables = "YES"
|
parallelizeBuildables = "YES"
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<Scheme
|
<Scheme
|
||||||
LastUpgradeVersion = "1300"
|
LastUpgradeVersion = "1310"
|
||||||
version = "1.3">
|
version = "1.3">
|
||||||
<BuildAction
|
<BuildAction
|
||||||
parallelizeBuildables = "YES"
|
parallelizeBuildables = "YES"
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<Scheme
|
<Scheme
|
||||||
LastUpgradeVersion = "1300"
|
LastUpgradeVersion = "1310"
|
||||||
version = "1.3">
|
version = "1.3">
|
||||||
<BuildAction
|
<BuildAction
|
||||||
parallelizeBuildables = "YES"
|
parallelizeBuildables = "YES"
|
||||||
|
@ -20,43 +20,8 @@ struct Player: UIViewControllerRepresentable {
|
|||||||
controller.playerModel = player
|
controller.playerModel = player
|
||||||
player.controller = controller
|
player.controller = controller
|
||||||
|
|
||||||
#if os(tvOS)
|
|
||||||
player.controller?.playerViewController.transportBarCustomMenuItems = [streamingQualityMenu]
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return controller
|
return controller
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateUIViewController(_: PlayerViewController, context _: Context) {
|
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
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user