1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-13 22:00:31 +05:30

Add playback mode menu in AVPlayer on tvOS

This commit is contained in:
Arkadiusz Fal 2022-08-26 01:59:42 +02:00
parent 6deaec90f8
commit 5c038b2aa7
2 changed files with 28 additions and 0 deletions

View File

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

View File

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