Skip to content

Commit

Permalink
fix issues with thumbnails
Browse files Browse the repository at this point in the history
fix #636
  • Loading branch information
lamarios committed Nov 21, 2024
1 parent 2b1ba04 commit b8ad7be
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 14 deletions.
5 changes: 4 additions & 1 deletion lib/player/views/components/audio_player.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:clipious/utils/models/image_object.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:clipious/player/views/components/player_controls.dart';
Expand Down Expand Up @@ -49,7 +50,9 @@ class AudioPlayer extends StatelessWidget {
decoration: const BoxDecoration(),
videoId: playerState.video!.videoId,
thumbnailUrl: playerState.video?.deArrowThumbnailUrl ??
playerState.video?.getBestThumbnail()?.url ??
ImageObject.getBestThumbnail(
playerState.video?.videoThumbnails ?? [])
?.url ??
'',
)
: playerState.offlineVideo != null
Expand Down
11 changes: 9 additions & 2 deletions lib/utils/models/image_object.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,17 @@ class ImageObject {
if (images != null && images.isNotEmpty) {
List<ImageObject> imgs = List.from(images);
imgs.sort((a, b) {
return (b.width * b.height).compareTo(a.width * a.height);
final aHasDefault = a.quality?.contains("default") ?? false;
final bHasDefault = b.quality?.contains("default") ?? false;

if (bHasDefault == aHasDefault) {
return (b.width * b.height).compareTo(a.width * a.height);
} else {
return (aHasDefault ? 0 : 1).compareTo(bHasDefault ? 0 : 1);
}
});

return imgs[0];
return imgs.firstOrNull;
} else {
return null;
}
Expand Down
9 changes: 0 additions & 9 deletions lib/videos/models/video.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,6 @@ class Video with _$Video implements ShareLinks, IdedVideo {

return link;
}

ImageObject? getBestThumbnail() {
if (videoThumbnails.isNotEmpty) {
return videoThumbnails
.firstWhere((element) => element.quality == 'maxres');
} else {
return null;
}
}
}

/*
Expand Down
4 changes: 3 additions & 1 deletion lib/videos/views/components/inner_view.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:clipious/utils/models/image_object.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
Expand Down Expand Up @@ -54,7 +55,8 @@ class VideoInnerView extends StatelessWidget {
child: VideoThumbnailView(
videoId: video.videoId,
thumbnailUrl: video.deArrowThumbnailUrl ??
video.getBestThumbnail()?.url ??
ImageObject.getBestThumbnail(video.videoThumbnails)
?.url ??
'',
child: phoneLandscape
? const SizedBox.shrink()
Expand Down
4 changes: 3 additions & 1 deletion lib/videos/views/components/inner_view_tablet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:clipious/videos/views/components/play_button.dart';
import '../../../player/states/player.dart';
import '../../../settings/states/settings.dart';
import '../../../utils.dart';
import '../../../utils/models/image_object.dart';
import '../../states/video.dart';
import 'add_to_queue_button.dart';
import 'info.dart';
Expand Down Expand Up @@ -56,7 +57,8 @@ class VideoTabletInnerView extends StatelessWidget {
child: VideoThumbnailView(
videoId: video.videoId,
thumbnailUrl: video.deArrowThumbnailUrl ??
video.getBestThumbnail()?.url ??
ImageObject.getBestThumbnail(video.videoThumbnails)
?.url ??
'',
child: Stack(
alignment: Alignment.center,
Expand Down

0 comments on commit b8ad7be

Please sign in to comment.