fix: thumbnail preview probe improvements
This commit is contained in:
@@ -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,
|
||||
),
|
||||
);
|
||||
},
|
||||
|
||||
@@ -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});
|
||||
|
||||
Reference in New Issue
Block a user