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

@ -1,3 +1,5 @@
import 'dart:math';
import 'package:flutter/material.dart';
import 'package:flutter_linkify/flutter_linkify.dart';
@ -36,11 +38,14 @@ class EventVideoPlayer extends StatelessWidget {
.tryGet<String>('xyz.amorgan.blurhash') ??
fallbackBlurHash;
final fileDescription = event.fileDescription;
const maxDimension = 300.0;
final infoMap = event.content.tryGetMap<String, Object?>('info');
final videoWidth = infoMap?.tryGet<int>('w') ?? 400;
final videoHeight = infoMap?.tryGet<int>('h') ?? 300;
const height = 300.0;
final width = videoWidth * (height / videoHeight);
final videoWidth = infoMap?.tryGet<int>('w') ?? maxDimension;
final videoHeight = infoMap?.tryGet<int>('h') ?? maxDimension;
final modifier = max(videoWidth, videoHeight) / maxDimension;
final width = videoWidth / modifier;
final height = videoHeight / modifier;
final durationInt = infoMap?.tryGet<int>('duration');
final duration =

View file

@ -59,16 +59,22 @@ class SendFileDialogState extends State<SendFileDialog> {
final length = await xfile.length();
final mimeType = xfile.mimeType ?? lookupMimeType(xfile.path);
// Generate video thumbnail
if (PlatformInfos.isMobile &&
mimeType != null &&
mimeType.startsWith('video')) {
scaffoldMessenger.showLoadingSnackBar(l10n.generatingVideoThumbnail);
thumbnail = await xfile.getVideoThumbnail();
}
// If file is a video, shrink it!
if (PlatformInfos.isMobile &&
mimeType != null &&
mimeType.startsWith('video') &&
length > minSizeToCompress &&
compress) {
mimeType.startsWith('video')) {
scaffoldMessenger.showLoadingSnackBar(l10n.compressVideo);
file = await xfile.resizeVideo();
scaffoldMessenger.showLoadingSnackBar(l10n.generatingVideoThumbnail);
thumbnail = await xfile.getVideoThumbnail();
file = await xfile.getVideoInfo(
compress: length > minSizeToCompress && compress,
);
} else {
if (length > maxUploadSize) {
throw FileTooBigMatrixException(length, maxUploadSize);