Improved thumbnail handling

- ThumbnailsModel optionally returns the quality
- Have constants for 4:3 and 16:9 aspect ratio
- Add high quality options for thumbnails
- Rename Highest quality to Best quality
- make 4:3 thumbnails fill the VideoCell
- use .maxes instead of .maxresdefault (the latter sometimes returns white images)

Signed-off-by: Toni Förster <toni.foerster@gmail.com>
This commit is contained in:
Toni Förster
2024-08-19 16:35:29 +02:00
parent af75afa912
commit 35534bcbb1
8 changed files with 31 additions and 39 deletions

View File

@@ -219,22 +219,18 @@ struct VideoBanner: View {
return watch!.finished ? 0.5 : 1
}
private var thumbnailWidth: Double {
#if os(tvOS)
356
#else
120
#endif
}
private var thumbnailHeight: Double {
#if os(tvOS)
200
#else
72
75
#endif
}
private var thumbnailWidth: Double {
thumbnailHeight * Constants.aspectRatio16x9
}
private var videoDurationLabel: String? {
guard videoDuration != 0 else { return nil }
return (videoDuration ?? video?.length)?.formattedAsPlaybackTime()

View File

@@ -440,7 +440,7 @@ struct VideoCell: View {
#endif
}
.mask(RoundedRectangle(cornerRadius: thumbnailRoundingCornerRadius))
.modifier(AspectRatioModifier())
.aspectRatio(Constants.aspectRatio16x9, contentMode: .fill)
}
private var time: String? {
@@ -471,24 +471,6 @@ struct VideoCell: View {
.lineLimit(lineLimit)
.truncationMode(.middle)
}
struct AspectRatioModifier: ViewModifier {
@Environment(\.horizontalCells) private var horizontalCells
func body(content: Content) -> some View {
Group {
if horizontalCells {
content
} else {
content
.aspectRatio(
VideoPlayerView.defaultAspectRatio,
contentMode: .fill
)
}
}
}
}
}
struct VideoCellThumbnail: View {
@@ -496,7 +478,15 @@ struct VideoCellThumbnail: View {
@ObservedObject private var thumbnails = ThumbnailsModel.shared
var body: some View {
ThumbnailView(url: thumbnails.best(video))
GeometryReader { geometry in
let (url, quality) = thumbnails.best(video)
let aspectRatio = (quality == .default || quality == .high) ? Constants.aspectRatio4x3 : Constants.aspectRatio16x9
ThumbnailView(url: url)
.aspectRatio(aspectRatio, contentMode: .fill)
.frame(width: geometry.size.width, height: geometry.size.height)
.clipped()
}
}
}