This commit is contained in:
Furkan 2023-01-01 17:55:42 +03:00
parent b0839394f6
commit 8d28cf590d

View File

@ -16,7 +16,7 @@ class MediaFile {
late String id; late String id;
bool thumbnailFailed = false; bool thumbnailFailed = false;
File? file; File? file;
bool _noMedium = false;
bool get isVideo => type == MediaType.video; bool get isVideo => type == MediaType.video;
bool get isImage => type == MediaType.image; bool get isImage => type == MediaType.image;
@ -27,6 +27,7 @@ class MediaFile {
id = medium.id; id = medium.id;
} }
MediaFile.file({required this.id, required this.file, required this.type}) { MediaFile.file({required this.id, required this.file, required this.type}) {
_noMedium = true;
medium = Medium( medium = Medium(
id: id, id: id,
mediumType: mediumType:
@ -34,21 +35,25 @@ class MediaFile {
} }
Future<Uint8List?> getThumbnail() async { Future<Uint8List?> getThumbnail() async {
try { if (thumbnail == null) {
if (file != null) { try {
thumbnail = await VideoThumbnail.thumbnailData( if (_noMedium) {
video: file!.path, thumbnail = isVideo
imageFormat: ImageFormat.JPEG, ? await VideoThumbnail.thumbnailData(
maxWidth: video: file!.path,
128, // specify the width of the thumbnail, let the height auto-scaled to keep the source aspect ratio imageFormat: ImageFormat.JPEG,
quality: 25, maxWidth:
); 128, // specify the width of the thumbnail, let the height auto-scaled to keep the source aspect ratio
} else { quality: 25,
thumbnail = )
Uint8List.fromList(await medium.getThumbnail(highQuality: true)); : await getData();
} else {
thumbnail =
Uint8List.fromList(await medium.getThumbnail(highQuality: true));
}
} catch (e) {
thumbnailFailed = true;
} }
} catch (e) {
thumbnailFailed = true;
} }
return thumbnail; return thumbnail;
} }
@ -66,7 +71,8 @@ class MediaFile {
if (file == null) { if (file == null) {
await getFile(); await getFile();
} }
data = await file!.readAsBytes(); data ??= await file!.readAsBytes();
return data!; return data!;
} }