fix compression video

This commit is contained in:
Salvatore Giordano
2020-11-30 18:07:11 +01:00
parent 48738c84c5
commit 46dcf6a629
+19 -5
View File
@@ -869,7 +869,7 @@ class MessageInputState extends State<MessageInput> {
} }
file = PlatformFile( file = PlatformFile(
name: file.name, name: file.name,
size: mediaInfo.filesize, size: (mediaInfo.filesize / 1024).ceil(),
bytes: await mediaInfo.file.readAsBytes(), bytes: await mediaInfo.file.readAsBytes(),
path: mediaInfo.path, path: mediaInfo.path,
); );
@@ -1294,6 +1294,12 @@ class MessageInputState extends State<MessageInput> {
? Image.memory( ? Image.memory(
attachment.file.bytes, attachment.file.bytes,
fit: BoxFit.cover, fit: BoxFit.cover,
errorBuilder: (context, _, __) {
return Image.asset(
'images/placeholder.png',
package: 'stream_chat_flutter',
);
},
) )
: Image.network( : Image.network(
attachment.attachment.imageUrl, attachment.attachment.imageUrl,
@@ -1520,6 +1526,7 @@ class MessageInputState extends State<MessageInput> {
} }
final bytes = await pickedFile.readAsBytes(); final bytes = await pickedFile.readAsBytes();
file = PlatformFile( file = PlatformFile(
size: (bytes.length / 1024).ceil(),
path: pickedFile.path, path: pickedFile.path,
bytes: bytes, bytes: bytes,
); );
@@ -1549,6 +1556,12 @@ class MessageInputState extends State<MessageInput> {
return; return;
} }
final mimeType = _getMimeType(file.name);
if (mimeType.type == 'video' || mimeType.type == 'image') {
attachmentType = mimeType.type;
}
final channel = StreamChannel.of(context).channel; final channel = StreamChannel.of(context).channel;
final attachment = _SendingAttachment( final attachment = _SendingAttachment(
file: file, file: file,
@@ -1562,17 +1575,18 @@ class MessageInputState extends State<MessageInput> {
_attachments.add(attachment); _attachments.add(attachment);
}); });
final mimeType = _getMimeType(file.name);
if (file.size > _kMaxAttachmentSize) { if (file.size > _kMaxAttachmentSize) {
if (attachmentType == 'video' || mimeType?.type == 'video') { if (attachmentType == 'video') {
final mediaInfo = await CompressVideoService.compressVideo(file.path); final mediaInfo = await CompressVideoService.compressVideo(file.path);
file = PlatformFile( file = PlatformFile(
name: mediaInfo.title, name: mediaInfo.title,
size: mediaInfo.filesize, size: (mediaInfo.filesize / 1024).ceil(),
bytes: await mediaInfo.file.readAsBytes(), bytes: await mediaInfo.file.readAsBytes(),
path: mediaInfo.path, path: mediaInfo.path,
); );
setState(() {
attachment.file = file;
});
} else { } else {
Scaffold.of(context).showSnackBar( Scaffold.of(context).showSnackBar(
SnackBar( SnackBar(