mirror of
https://github.com/yattee/yattee.git
synced 2025-08-05 02:04:07 +00:00
Add tvOS streams selection
This commit is contained in:
@@ -139,14 +139,10 @@ struct PlaybackBar: View {
|
||||
}
|
||||
|
||||
private func availableStreamsForInstance(_ instance: Instance) -> [Stream.Kind: [Stream]] {
|
||||
let streams = player.availableStreams.filter { $0.instance == instance }.sorted(by: streamsSorter)
|
||||
let streams = player.availableStreams.filter { $0.instance == instance }.sorted(by: player.streamsSorter)
|
||||
|
||||
return Dictionary(grouping: streams, by: \.kind!)
|
||||
}
|
||||
|
||||
private func streamsSorter(_ lhs: Stream, _ rhs: Stream) -> Bool {
|
||||
lhs.kind == rhs.kind ? (lhs.resolution.height > rhs.resolution.height) : (lhs.kind < rhs.kind)
|
||||
}
|
||||
}
|
||||
|
||||
struct PlaybackBar_Previews: PreviewProvider {
|
||||
|
@@ -20,8 +20,37 @@ 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) {}
|
||||
func updateUIViewController(_: PlayerViewController, context _: Context) {
|
||||
#if os(tvOS)
|
||||
player.controller?.playerViewController.transportBarCustomMenuItems = [streamingQualityMenu]
|
||||
#endif
|
||||
}
|
||||
|
||||
#if os(tvOS)
|
||||
var streamingQualityMenu: UIMenu {
|
||||
UIMenu(
|
||||
title: "Streaming quality",
|
||||
image: UIImage(systemName: "antenna.radiowaves.left.and.right"),
|
||||
children: streamingQualityMenuActions
|
||||
)
|
||||
}
|
||||
|
||||
var streamingQualityMenuActions: [UIAction] {
|
||||
player.availableStreamsSorted.map { stream in
|
||||
let image = player.streamSelection == stream ? UIImage(systemName: "checkmark") : nil
|
||||
|
||||
return UIAction(title: stream.description, image: image) { _ in
|
||||
self.player.streamSelection = stream
|
||||
self.player.upgradeToStream(stream)
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
Reference in New Issue
Block a user