From cbd1102563e9d86a31f917e94750c1f90b39bd0d Mon Sep 17 00:00:00 2001 From: Arkadiusz Fal Date: Fri, 26 Aug 2022 01:59:42 +0200 Subject: [PATCH] Add playback mode menu in AVPlayer on tvOS --- Model/Player/PlayerModel.swift | 13 +++++++++++++ Model/Player/PlayerTVMenu.swift | 15 +++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/Model/Player/PlayerModel.swift b/Model/Player/PlayerModel.swift index 5920d74a..75d24d96 100644 --- a/Model/Player/PlayerModel.swift +++ b/Model/Player/PlayerModel.swift @@ -30,6 +30,19 @@ final class PlayerModel: ObservableObject { return "infinity" } } + + var description: String { + switch self { + case .queue: + return "Queue" + case .shuffle: + return "Queue, shuffled" + case .loopOne: + return "Loop one" + case .related: + return "Autoplay next" + } + } } static let availableRates: [Float] = [0.5, 0.67, 0.8, 1, 1.25, 1.5, 2] diff --git a/Model/Player/PlayerTVMenu.swift b/Model/Player/PlayerTVMenu.swift index ce2ac2e4..352f00ca 100644 --- a/Model/Player/PlayerTVMenu.swift +++ b/Model/Player/PlayerTVMenu.swift @@ -69,6 +69,20 @@ extension PlayerModel { } } } + + private var playbackModeMenu: UIMenu { + UIMenu(title: "Playback Mode", image: UIImage(systemName: playbackMode.systemImage), children: playbackModeMenuActions) + } + + private var playbackModeMenuActions: [UIAction] { + PlaybackMode.allCases.map { mode in + UIAction(title: mode.description, image: UIImage(systemName: mode.systemImage)) { _ in + DispatchQueue.main.async { + self.playbackMode = mode + } + } + } + } #endif func rebuildTVMenu() { @@ -77,6 +91,7 @@ extension PlayerModel { restoreLastSkippedSegmentAction, rateMenu, streamsMenu, + playbackModeMenu, switchToMPVAction ].compactMap { $0 } #endif