Skip to content

Commit

Permalink
Improve video quality selection
Browse files Browse the repository at this point in the history
  • Loading branch information
Jman012 committed Jun 10, 2023
1 parent 9b8a951 commit bae0e2c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Wasserflug-tvOS/SupplementalViews/VideoPlayerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ struct VideoPlayerView: UIViewControllerRepresentable {
let sparkleTvImage = UIImage(systemName: "sparkles.tv")
let resolutions: [UIAction] = viewModel.qualityLevels.values
.sorted(by: { $0.1.order ?? 0 < $1.1.order ?? 0 })
.reversed()
.reversed() // This keeps the higher quality on top of the menu
.map({ (qualityLevel) -> UIAction in
return UIAction(title: qualityLevel.1.label, identifier: UIAction.Identifier(qualityLevel.1.name), handler: { _ in
UserDefaults.standard.set(qualityLevel.1.name, forKey: "DesiredQuality")
Expand Down
10 changes: 7 additions & 3 deletions Wasserflug-tvOS/ViewModels/VideoViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,13 @@ class VideoViewModel: BaseViewModel, ObservableObject {
])
var url = qualityLevels[desiredQuality]?.0
if url == nil {
url = qualityLevels
.sorted(by: { Int($0.key) ?? 0 < Int($1.key) ?? 0 })
.filter({ Int($0.key) ?? 0 < Int(desiredQuality) ?? Int.max }) // Don't get a resolution larger than the desired.
let sortedUrls = qualityLevels
.sorted(by: { $0.value.1.meta?.video?.height ?? 0 < $1.value.1.meta?.video?.height ?? 0 })
// Just get the highest available. It's difficult to be smart about next highest from the selection, because the label isn't
// sortable, so let's just guess that if a desired quality isn't available, it's because it was too high and this video
// doesn't have it, but the user wants higher quality. It's also an Apple TV instead of a mobiel device, so higher quality
// is expected. The expected use case is 4K is desired, but only up to 1080p is available, so default to 1080p.
url = sortedUrls
.last?
.value.0
}
Expand Down

0 comments on commit bae0e2c

Please sign in to comment.