refactor(ui): remove video compression
Signed-off-by: xsahil03x <[email protected]>
This commit is contained in:
@@ -18,12 +18,8 @@ import 'package:stream_chat_flutter/src/media_list_view.dart';
|
||||
import 'package:stream_chat_flutter/src/multi_overlay.dart';
|
||||
import 'package:stream_chat_flutter/src/quoted_message_widget.dart';
|
||||
import 'package:stream_chat_flutter/src/user_mentions_overlay.dart';
|
||||
import 'package:stream_chat_flutter/src/video_service.dart';
|
||||
import 'package:stream_chat_flutter/src/video_thumbnail_image.dart';
|
||||
import 'package:stream_chat_flutter/stream_chat_flutter.dart';
|
||||
import 'package:video_compress/video_compress.dart';
|
||||
|
||||
export 'package:video_compress/video_compress.dart' show VideoQuality;
|
||||
|
||||
/// A callback that can be passed to [MessageInput.onError].
|
||||
///
|
||||
@@ -191,8 +187,6 @@ class MessageInput extends StatefulWidget {
|
||||
this.mentionsTileBuilder,
|
||||
this.userMentionsTileBuilder,
|
||||
this.maxAttachmentSize = _kDefaultMaxAttachmentSize,
|
||||
this.compressedVideoQuality = VideoQuality.DefaultQuality,
|
||||
this.compressedVideoFrameRate = 30,
|
||||
this.onError,
|
||||
this.attachmentLimit = 10,
|
||||
this.onAttachmentLimitExceed,
|
||||
@@ -213,12 +207,6 @@ class MessageInput extends StatefulWidget {
|
||||
/// 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
|
||||
@@ -1119,41 +1107,18 @@ class MessageInputState extends State<MessageInput> {
|
||||
|
||||
if (mediaFile == null) return;
|
||||
|
||||
var file = AttachmentFile(
|
||||
final file = AttachmentFile(
|
||||
path: mediaFile.path,
|
||||
size: await mediaFile.length(),
|
||||
bytes: mediaFile.readAsBytesSync(),
|
||||
);
|
||||
|
||||
if (file.size! > widget.maxAttachmentSize) {
|
||||
if (medium.type == AssetType.video && file.path != null) {
|
||||
final mediaInfo = await StreamVideoService.compressVideo(
|
||||
file.path!,
|
||||
frameRate: widget.compressedVideoFrameRate,
|
||||
quality: widget.compressedVideoQuality,
|
||||
);
|
||||
|
||||
if (mediaInfo == null ||
|
||||
mediaInfo.filesize! > widget.maxAttachmentSize) {
|
||||
_showErrorAlert(
|
||||
context.translations.fileTooLargeAfterCompressionError(
|
||||
widget.maxAttachmentSize / (1024 * 1024),
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
file = AttachmentFile(
|
||||
name: file.name,
|
||||
size: mediaInfo.filesize,
|
||||
bytes: await mediaInfo.file?.readAsBytes(),
|
||||
path: mediaInfo.path,
|
||||
);
|
||||
} else {
|
||||
_showErrorAlert(context.translations.fileTooLargeError(
|
||||
return _showErrorAlert(
|
||||
context.translations.fileTooLargeError(
|
||||
widget.maxAttachmentSize / (1024 * 1024),
|
||||
));
|
||||
return;
|
||||
}
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
setState(() {
|
||||
@@ -1678,33 +1643,11 @@ class MessageInputState extends State<MessageInput> {
|
||||
);
|
||||
|
||||
if (file.size! > widget.maxAttachmentSize) {
|
||||
if (attachmentType == 'video' && file.path != null) {
|
||||
final mediaInfo = await (StreamVideoService.compressVideo(
|
||||
file.path!,
|
||||
frameRate: widget.compressedVideoFrameRate,
|
||||
quality: widget.compressedVideoQuality,
|
||||
) as FutureOr<MediaInfo>);
|
||||
|
||||
if (mediaInfo.filesize! > widget.maxAttachmentSize) {
|
||||
_showErrorAlert(
|
||||
context.translations.fileTooLargeAfterCompressionError(
|
||||
widget.maxAttachmentSize / (1024 * 1024),
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
file = AttachmentFile(
|
||||
name: file.name,
|
||||
size: mediaInfo.filesize,
|
||||
bytes: await mediaInfo.file!.readAsBytes(),
|
||||
path: mediaInfo.path,
|
||||
);
|
||||
} else {
|
||||
_showErrorAlert(context.translations.fileTooLargeError(
|
||||
return _showErrorAlert(
|
||||
context.translations.fileTooLargeError(
|
||||
widget.maxAttachmentSize / (1024 * 1024),
|
||||
));
|
||||
return;
|
||||
}
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
setState(() {
|
||||
|
||||
@@ -18,12 +18,8 @@ import 'package:stream_chat_flutter/src/message_input/tld.dart';
|
||||
import 'package:stream_chat_flutter/src/multi_overlay.dart';
|
||||
import 'package:stream_chat_flutter/src/quoted_message_widget.dart';
|
||||
import 'package:stream_chat_flutter/src/user_mentions_overlay.dart';
|
||||
import 'package:stream_chat_flutter/src/video_service.dart';
|
||||
import 'package:stream_chat_flutter/src/video_thumbnail_image.dart';
|
||||
import 'package:stream_chat_flutter/stream_chat_flutter.dart';
|
||||
import 'package:video_compress/video_compress.dart';
|
||||
|
||||
export 'package:video_compress/video_compress.dart' show VideoQuality;
|
||||
|
||||
/// A function that returns true if the message is valid and can be sent.
|
||||
typedef MessageValidator = bool Function(Message message);
|
||||
@@ -202,8 +198,6 @@ class StreamMessageInput extends StatefulWidget {
|
||||
this.mentionsTileBuilder,
|
||||
this.userMentionsTileBuilder,
|
||||
this.maxAttachmentSize = _kDefaultMaxAttachmentSize,
|
||||
this.compressedVideoQuality = VideoQuality.DefaultQuality,
|
||||
this.compressedVideoFrameRate = 30,
|
||||
this.onError,
|
||||
this.attachmentLimit = 10,
|
||||
this.onAttachmentLimitExceed,
|
||||
@@ -224,12 +218,6 @@ class StreamMessageInput extends StatefulWidget {
|
||||
/// List of options for showing overlays.
|
||||
final List<OverlayOptions> customOverlays;
|
||||
|
||||
/// 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
|
||||
@@ -1126,8 +1114,6 @@ class StreamMessageInputState extends State<StreamMessageInput>
|
||||
attachmentLimit: widget.attachmentLimit,
|
||||
onAttachmentLimitExceeded: widget.onAttachmentLimitExceed,
|
||||
maxAttachmentSize: widget.maxAttachmentSize,
|
||||
compressedVideoQuality: widget.compressedVideoQuality,
|
||||
compressedVideoFrameRate: widget.compressedVideoFrameRate,
|
||||
onError: _showErrorAlert,
|
||||
);
|
||||
|
||||
@@ -1639,33 +1625,11 @@ class StreamMessageInputState extends State<StreamMessageInput>
|
||||
);
|
||||
|
||||
if (file.size! > widget.maxAttachmentSize) {
|
||||
if (attachmentType == 'video' && file.path != null) {
|
||||
final mediaInfo = await (StreamVideoService.compressVideo(
|
||||
file.path!,
|
||||
frameRate: widget.compressedVideoFrameRate,
|
||||
quality: widget.compressedVideoQuality,
|
||||
) as FutureOr<MediaInfo>);
|
||||
|
||||
if (mediaInfo.filesize! > widget.maxAttachmentSize) {
|
||||
_showErrorAlert(
|
||||
context.translations.fileTooLargeAfterCompressionError(
|
||||
widget.maxAttachmentSize / (1024 * 1024),
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
file = AttachmentFile(
|
||||
name: file.name,
|
||||
size: mediaInfo.filesize,
|
||||
bytes: await mediaInfo.file!.readAsBytes(),
|
||||
path: mediaInfo.path,
|
||||
);
|
||||
} else {
|
||||
_showErrorAlert(context.translations.fileTooLargeError(
|
||||
return _showErrorAlert(
|
||||
context.translations.fileTooLargeError(
|
||||
widget.maxAttachmentSize / (1024 * 1024),
|
||||
));
|
||||
return;
|
||||
}
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
_addAttachments([
|
||||
|
||||
@@ -5,9 +5,7 @@ import 'package:flutter_svg/flutter_svg.dart';
|
||||
import 'package:photo_manager/photo_manager.dart';
|
||||
import 'package:stream_chat_flutter/src/extension.dart';
|
||||
import 'package:stream_chat_flutter/src/media_list_view.dart';
|
||||
import 'package:stream_chat_flutter/src/video_service.dart';
|
||||
import 'package:stream_chat_flutter/stream_chat_flutter.dart';
|
||||
import 'package:video_compress/video_compress.dart';
|
||||
|
||||
/// Callback for when a file has to be picked.
|
||||
typedef FilePickerCallback = void Function(
|
||||
@@ -34,8 +32,6 @@ class StreamAttachmentPicker extends StatefulWidget {
|
||||
this.attachmentLimit = 10,
|
||||
this.onAttachmentLimitExceeded,
|
||||
this.maxAttachmentSize = 20971520,
|
||||
this.compressedVideoQuality = VideoQuality.DefaultQuality,
|
||||
this.compressedVideoFrameRate = 30,
|
||||
this.onError,
|
||||
this.allowedAttachmentTypes = const [
|
||||
DefaultAttachmentTypes.image,
|
||||
@@ -66,12 +62,6 @@ class StreamAttachmentPicker extends StatefulWidget {
|
||||
/// Callback for when file is picked.
|
||||
final FilePickerCallback onFilePicked;
|
||||
|
||||
/// 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
|
||||
@@ -94,8 +84,6 @@ class StreamAttachmentPicker extends StatefulWidget {
|
||||
int? attachmentLimit,
|
||||
AttachmentLimitExceedListener? onAttachmentLimitExceeded,
|
||||
int? maxAttachmentSize,
|
||||
VideoQuality? compressedVideoQuality,
|
||||
int? compressedVideoFrameRate,
|
||||
ValueChanged<bool>? onChangeInputState,
|
||||
ValueChanged<String>? onError,
|
||||
List<DefaultAttachmentTypes>? allowedAttachmentTypes,
|
||||
@@ -112,10 +100,6 @@ class StreamAttachmentPicker extends StatefulWidget {
|
||||
onAttachmentLimitExceeded:
|
||||
onAttachmentLimitExceeded ?? this.onAttachmentLimitExceeded,
|
||||
maxAttachmentSize: maxAttachmentSize ?? this.maxAttachmentSize,
|
||||
compressedVideoQuality:
|
||||
compressedVideoQuality ?? this.compressedVideoQuality,
|
||||
compressedVideoFrameRate:
|
||||
compressedVideoFrameRate ?? this.compressedVideoFrameRate,
|
||||
onError: onError ?? this.onError,
|
||||
allowedAttachmentTypes:
|
||||
allowedAttachmentTypes ?? this.allowedAttachmentTypes,
|
||||
@@ -375,33 +359,11 @@ class _StreamAttachmentPickerState extends State<StreamAttachmentPicker> {
|
||||
);
|
||||
|
||||
if (file.size! > widget.maxAttachmentSize) {
|
||||
if (medium.type == AssetType.video && file.path != null) {
|
||||
final mediaInfo = await (StreamVideoService.compressVideo(
|
||||
file.path!,
|
||||
frameRate: widget.compressedVideoFrameRate,
|
||||
quality: widget.compressedVideoQuality,
|
||||
) as FutureOr<MediaInfo>);
|
||||
|
||||
if (mediaInfo.filesize! > widget.maxAttachmentSize) {
|
||||
widget.onError?.call(
|
||||
context.translations.fileTooLargeAfterCompressionError(
|
||||
widget.maxAttachmentSize / (1024 * 1024),
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
file = AttachmentFile(
|
||||
name: file.name,
|
||||
size: mediaInfo.filesize,
|
||||
bytes: await mediaInfo.file?.readAsBytes(),
|
||||
path: mediaInfo.path,
|
||||
);
|
||||
} else {
|
||||
widget.onError?.call(context.translations.fileTooLargeError(
|
||||
return widget.onError?.call(
|
||||
context.translations.fileTooLargeError(
|
||||
widget.maxAttachmentSize / (1024 * 1024),
|
||||
));
|
||||
return;
|
||||
}
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
setState(() {
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import 'dart:async';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:synchronized/synchronized.dart';
|
||||
import 'package:video_compress/video_compress.dart';
|
||||
import 'package:video_thumbnail/video_thumbnail.dart';
|
||||
|
||||
///
|
||||
@@ -12,32 +10,6 @@ class _IVideoService {
|
||||
|
||||
/// Singleton instance of [_IVideoService]
|
||||
static final _IVideoService instance = _IVideoService._();
|
||||
final _lock = Lock();
|
||||
|
||||
/// compress video from [path]
|
||||
/// compress video from [path] return [Future<MediaInfo>]
|
||||
///
|
||||
/// you can choose its [quality] and [frameRate]
|
||||
///
|
||||
/// ## example
|
||||
/// ```dart
|
||||
/// final info = await _flutterVideoCompress.compressVideo(
|
||||
/// file.path,
|
||||
/// );
|
||||
/// debugPrint(info.toJson());
|
||||
/// ```
|
||||
Future<MediaInfo?> compressVideo(
|
||||
String path, {
|
||||
int frameRate = 30,
|
||||
VideoQuality quality = VideoQuality.DefaultQuality,
|
||||
}) async =>
|
||||
_lock.synchronized(
|
||||
() => VideoCompress.compressVideo(
|
||||
path,
|
||||
frameRate: frameRate,
|
||||
quality: quality,
|
||||
),
|
||||
);
|
||||
|
||||
/// Generates a thumbnail image data in memory as UInt8List,
|
||||
/// it can be easily used by Image.memory(...).
|
||||
|
||||
@@ -38,9 +38,7 @@ dependencies:
|
||||
shimmer: ^2.0.0
|
||||
stream_chat_flutter_core: ^3.5.0
|
||||
substring_highlight: ^1.0.26
|
||||
synchronized: ^3.0.0
|
||||
url_launcher: ^6.0.3
|
||||
video_compress: ^3.0.0
|
||||
video_player: ^2.1.0
|
||||
video_thumbnail: ^0.4.3
|
||||
visibility_detector: ^0.2.0
|
||||
|
||||
Reference in New Issue
Block a user