fix: Workaround for reversed width and height of compressed videos sent from Android

This commit is contained in:
Christian Kußowski 2025-06-21 10:05:14 +02:00
commit 3d0a3ee226
No known key found for this signature in database
GPG key ID: E067ECD60F1A0652
3 changed files with 31 additions and 15 deletions

View file

@ -8,22 +8,27 @@ extension ResizeImage on XFile {
static const int max = 1200;
static const int quality = 40;
Future<MatrixVideoFile> resizeVideo() async {
Future<MatrixVideoFile> getVideoInfo({bool compress = true}) async {
MediaInfo? mediaInfo;
try {
if (PlatformInfos.isMobile) {
// will throw an error e.g. on Android SDK < 18
mediaInfo = await VideoCompress.compressVideo(path);
mediaInfo = compress
? await VideoCompress.compressVideo(path, deleteOrigin: true)
: await VideoCompress.getMediaInfo(path);
}
} catch (e, s) {
Logs().w('Error while compressing video', e, s);
Logs().w('Error while fetching video media info', e, s);
}
return MatrixVideoFile(
bytes: (await mediaInfo?.file?.readAsBytes()) ?? await readAsBytes(),
name: name,
mimeType: mimeType,
width: mediaInfo?.width,
height: mediaInfo?.height,
// on Android width and height is reversed:
// https://github.com/jonataslaw/VideoCompress/issues/172
width: PlatformInfos.isAndroid ? mediaInfo?.height : mediaInfo?.width,
height: PlatformInfos.isAndroid ? mediaInfo?.width : mediaInfo?.height,
duration: mediaInfo?.duration?.round(),
);
}