You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.3 KiB
Dart
47 lines
1.3 KiB
Dart
5 months ago
|
import 'package:cross_file/cross_file.dart';
|
||
3 years ago
|
import 'package:matrix/matrix.dart';
|
||
3 years ago
|
import 'package:video_compress/video_compress.dart';
|
||
|
|
||
|
import 'package:fluffychat/utils/platform_infos.dart';
|
||
4 years ago
|
|
||
5 months ago
|
extension ResizeImage on XFile {
|
||
3 years ago
|
static const int max = 1200;
|
||
|
static const int quality = 40;
|
||
3 years ago
|
|
||
3 years ago
|
Future<MatrixVideoFile> resizeVideo() async {
|
||
|
MediaInfo? mediaInfo;
|
||
|
try {
|
||
5 months ago
|
if (PlatformInfos.isMobile) {
|
||
|
// will throw an error e.g. on Android SDK < 18
|
||
|
mediaInfo = await VideoCompress.compressVideo(path);
|
||
|
}
|
||
3 years ago
|
} catch (e, s) {
|
||
3 years ago
|
Logs().w('Error while compressing video', e, s);
|
||
3 years ago
|
}
|
||
3 years ago
|
return MatrixVideoFile(
|
||
5 months ago
|
bytes: (await mediaInfo?.file?.readAsBytes()) ?? await readAsBytes(),
|
||
3 years ago
|
name: name,
|
||
|
mimeType: mimeType,
|
||
|
width: mediaInfo?.width,
|
||
|
height: mediaInfo?.height,
|
||
|
duration: mediaInfo?.duration?.round(),
|
||
|
);
|
||
3 years ago
|
}
|
||
|
|
||
|
Future<MatrixImageFile?> getVideoThumbnail() async {
|
||
|
if (!PlatformInfos.isMobile) return null;
|
||
5 months ago
|
|
||
3 years ago
|
try {
|
||
5 months ago
|
final bytes = await VideoCompress.getByteThumbnail(path);
|
||
3 years ago
|
if (bytes == null) return null;
|
||
|
return MatrixImageFile(
|
||
|
bytes: bytes,
|
||
|
name: name,
|
||
3 years ago
|
);
|
||
3 years ago
|
} catch (e, s) {
|
||
3 years ago
|
Logs().w('Error while compressing video', e, s);
|
||
3 years ago
|
}
|
||
|
return null;
|
||
|
}
|
||
4 years ago
|
}
|