Add tvOS streams selection

This commit is contained in:
Arkadiusz Fal
2021-10-17 23:49:56 +02:00
parent 62e17d5a18
commit 0d1eaaca5c
7 changed files with 49 additions and 12 deletions

View File

@@ -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
}