1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-22 21:09:21 +00:00
comunicmobile/lib/utils/video_utils.dart

38 lines
866 B
Dart
Raw Normal View History

2021-03-12 18:36:42 +00:00
import 'dart:io';
import 'package:comunic/models/api_request.dart';
import 'package:comunic/utils/log_utils.dart';
import 'package:flutter/material.dart';
import 'package:video_thumbnail/video_thumbnail.dart';
2021-03-13 16:50:59 +00:00
import 'files_utils.dart';
2021-03-12 18:36:42 +00:00
/// Video utilities
///
/// @author Pierre Hubert
/// Generate a thumbnail for a video. In case of failure, return null
Future<BytesFile> generateVideoThumbnail({
@required BytesFile videoFile,
int maxWidth,
}) async {
File file;
try {
2021-03-13 16:50:59 +00:00
file = await generateTemporaryFile();
2021-03-12 18:36:42 +00:00
await file.writeAsBytes(videoFile.bytes);
return BytesFile(
"thumb.png",
await VideoThumbnail.thumbnailData(
video: file.absolute.path, maxWidth: maxWidth),
);
} catch (e, s) {
logError(e, s);
return null;
} finally {
if (file != null && await file.exists()) await file.delete();
}
}