From 0379a1776727aea6cd90e3675720f2eda758a0e7 Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Tue, 6 Jul 2021 13:20:34 +0200 Subject: [PATCH] add video compress options (frame and quality) to message input --- .../lib/src/message_input.dart | 24 +++++++++++++++---- .../lib/src/video_service.dart | 14 +++++++---- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/packages/stream_chat_flutter/lib/src/message_input.dart b/packages/stream_chat_flutter/lib/src/message_input.dart index a0ff93cf..c4a665e6 100644 --- a/packages/stream_chat_flutter/lib/src/message_input.dart +++ b/packages/stream_chat_flutter/lib/src/message_input.dart @@ -25,6 +25,8 @@ import 'package:stream_chat_flutter_core/stream_chat_flutter_core.dart'; import 'package:substring_highlight/substring_highlight.dart'; import 'package:video_compress/video_compress.dart'; +export 'package:video_compress/video_compress.dart' show VideoQuality; + /// Builder for attachment thumbnails typedef AttachmentThumbnailBuilder = Widget Function( BuildContext, @@ -149,11 +151,19 @@ class MessageInput extends StatefulWidget { this.showCommandsButton = true, this.mentionsTileBuilder, this.maxAttachmentSize = _kDefaultMaxAttachmentSize, + this.compressedVideoQuality = VideoQuality.DefaultQuality, + this.compressedVideoFrameRate = 30, }) : super(key: key); /// Message to edit final Message? editMessage; + /// Video quality to use when compressing the videos + final VideoQuality compressedVideoQuality; + + /// Frame rate to use when compressing the videos + final int compressedVideoFrameRate; + /// Max attachment size in bytes /// Defaults to 20 MB /// do not set it if you're using our default CDN @@ -1116,8 +1126,11 @@ class MessageInputState extends State { if (file.size! > widget.maxAttachmentSize) { if (medium.type == AssetType.video && file.path != null) { - final mediaInfo = await (VideoService.compressVideo(file.path!) - as FutureOr); + final mediaInfo = await (VideoService.compressVideo( + file.path!, + frameRate: widget.compressedVideoFrameRate, + quality: widget.compressedVideoQuality, + ) as FutureOr); if (mediaInfo.filesize! > widget.maxAttachmentSize) { _showErrorAlert( @@ -1892,8 +1905,11 @@ class MessageInputState extends State { if (file.size! > widget.maxAttachmentSize) { if (attachmentType == 'video' && file.path != null) { - final mediaInfo = await (VideoService.compressVideo(file.path!) - as FutureOr); + final mediaInfo = await (VideoService.compressVideo( + file.path!, + frameRate: widget.compressedVideoFrameRate, + quality: widget.compressedVideoQuality, + ) as FutureOr); if (mediaInfo.filesize! > widget.maxAttachmentSize) { _showErrorAlert( diff --git a/packages/stream_chat_flutter/lib/src/video_service.dart b/packages/stream_chat_flutter/lib/src/video_service.dart index 290dd54b..e914f466 100644 --- a/packages/stream_chat_flutter/lib/src/video_service.dart +++ b/packages/stream_chat_flutter/lib/src/video_service.dart @@ -16,21 +16,25 @@ class IVideoService { /// compress video from [path] /// compress video from [path] return [Future] /// - /// you can choose its quality by [quality], - /// determine whether to delete his source file by [deleteOrigin] - /// optional parameters [startTime] [duration] [includeAudio] [frameRate] + /// you can choose its [quality] and [frameRate] /// /// ## example /// ```dart /// final info = await _flutterVideoCompress.compressVideo( /// file.path, - /// deleteOrigin: true, /// ); /// debugPrint(info.toJson()); /// ``` - Future compressVideo(String path) async => _lock.synchronized( + Future compressVideo( + String path, { + int frameRate = 30, + VideoQuality quality = VideoQuality.DefaultQuality, + }) async => + _lock.synchronized( () => VideoCompress.compressVideo( path, + frameRate: frameRate, + quality: quality, ), );