fix: thumbnail preview probe improvements

This commit is contained in:
edde746
2026-02-07 20:57:12 +01:00
parent d76f1ed562
commit 05abf40c59
2 changed files with 25 additions and 7 deletions
+11 -7
View File
@@ -876,12 +876,14 @@ class VideoPlayerScreenState extends State<VideoPlayerScreen> with WidgetsBindin
// Check whether any thumbnails exist by requesting the first one
if (_currentMediaInfo?.partId != null && !widget.isOffline) {
final url = _buildThumbnailUrl(context, Duration.zero);
if (url != null) {
HttpClient().getUrl(Uri.parse(url)).then((req) => req.close()).then((res) {
if (mounted) setState(() => _hasThumbnails = res.statusCode == 200);
}).catchError((_) {});
}
final partId = _currentMediaInfo!.partId!;
final client = _getClientForMetadata(context);
client.checkThumbnailsAvailable(partId).then((available) {
// Guard against media having changed while the probe was in flight
if (mounted && _currentMediaInfo?.partId == partId) {
setState(() => _hasThumbnails = available);
}
});
}
// Initialize video PIP and filter manager with player and available versions
@@ -1888,7 +1890,9 @@ class VideoPlayerScreenState extends State<VideoPlayerScreen> with WidgetsBindin
controlsVisible: _controlsVisible,
shaderService: _shaderService,
onShaderChanged: () => setState(() {}),
thumbnailUrlBuilder: _hasThumbnails ? (Duration time) => _buildThumbnailUrl(context, time)! : null,
thumbnailUrlBuilder: _hasThumbnails && _currentMediaInfo?.partId != null
? (Duration time) => _buildThumbnailUrl(context, time)!
: null,
),
);
},
+14
View File
@@ -754,6 +754,20 @@ class PlexClient {
return '${config.baseUrl}/$path'.withPlexToken(config.token);
}
/// Check whether thumbnail previews are available for a given part.
/// Returns true if the server responds with 200 to the first thumbnail.
Future<bool> checkThumbnailsAvailable(int partId) async {
try {
final response = await _dio.get(
'/library/parts/$partId/indexes/sd/0',
options: Options(responseType: ResponseType.bytes, receiveTimeout: const Duration(seconds: 5)),
);
return response.statusCode == 200;
} catch (_) {
return false;
}
}
/// Get chapters for a media item
Future<List<PlexChapter>> getChapters(String ratingKey) async {
final response = await _dio.get('/library/metadata/$ratingKey', queryParameters: {'includeChapters': 1});