compress videos
This commit is contained in:
@@ -185,26 +185,25 @@ class _ChannelListViewState extends State<ChannelListView>
|
||||
child = widget.emptyBuilder(context);
|
||||
}
|
||||
|
||||
if (channels.isEmpty && widget.emptyBuilder == null) {
|
||||
child = LayoutBuilder(
|
||||
builder: (context, viewportConstraints) {
|
||||
return SingleChildScrollView(
|
||||
physics: AlwaysScrollableScrollPhysics(),
|
||||
child: Stack(
|
||||
children: [
|
||||
ConstrainedBox(
|
||||
constraints: BoxConstraints(
|
||||
minHeight: viewportConstraints.maxHeight,
|
||||
),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: StreamSvgIcon.message(
|
||||
size: 136,
|
||||
color: Color(0xffDBDBDB),
|
||||
),
|
||||
if (channels.isEmpty && widget.emptyBuilder == null) {
|
||||
child = LayoutBuilder(
|
||||
builder: (context, viewportConstraints) {
|
||||
return SingleChildScrollView(
|
||||
physics: AlwaysScrollableScrollPhysics(),
|
||||
child: Stack(
|
||||
children: [
|
||||
ConstrainedBox(
|
||||
constraints: BoxConstraints(
|
||||
minHeight: viewportConstraints.maxHeight,
|
||||
),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: StreamSvgIcon.message(
|
||||
size: 136,
|
||||
color: Color(0xffDBDBDB),
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
import 'dart:async';
|
||||
import 'package:video_compress/video_compress.dart';
|
||||
|
||||
class CompressVideoService {
|
||||
static final CompressVideoService instance = CompressVideoService._();
|
||||
|
||||
CompressVideoService._();
|
||||
|
||||
Future<MediaInfo> compressVideo(String path) async {
|
||||
MediaInfo mediaInfo;
|
||||
while (VideoCompress.isCompressing) {
|
||||
await Future.delayed(Duration(seconds: 1));
|
||||
}
|
||||
mediaInfo = await VideoCompress.compressVideo(
|
||||
path,
|
||||
);
|
||||
return mediaInfo;
|
||||
}
|
||||
}
|
||||
+15
-41
@@ -14,6 +14,7 @@ import 'package:media_gallery/media_gallery.dart';
|
||||
import 'package:mime/mime.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:stream_chat/stream_chat.dart';
|
||||
import 'package:stream_chat_flutter/src/compress_video_service.dart';
|
||||
import 'package:stream_chat_flutter/src/media_list_view.dart';
|
||||
import 'package:stream_chat_flutter/src/message_list_view.dart';
|
||||
import 'package:stream_chat_flutter/src/stream_chat_theme.dart';
|
||||
@@ -865,7 +866,18 @@ class MessageInputState extends State<MessageInput> {
|
||||
|
||||
if (file.size > _kMaxAttachmentSize) {
|
||||
if (medium.mediaType == MediaType.video) {
|
||||
final mediaInfo = await _compressVideo(file);
|
||||
final mediaInfo =
|
||||
await CompressVideoService.instance.compressVideo(file.path);
|
||||
|
||||
if (mediaInfo.filesize / (1024 * 1024) > _kMaxAttachmentSize) {
|
||||
Scaffold.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
'The file is too large to upload. The file size limit is 20MB. We tried compressing it, but it was not enough.',
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
file = PlatformFile(
|
||||
name: file.name,
|
||||
size: mediaInfo.filesize,
|
||||
@@ -929,33 +941,6 @@ class MessageInputState extends State<MessageInput> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<MediaInfo> _compressVideo(PlatformFile file) async {
|
||||
print('file.size: ${file.size}');
|
||||
print('VideoCompress.isCompressing: ${VideoCompress.isCompressing}');
|
||||
if (VideoCompress.isCompressing) {
|
||||
final compressCompleter = Completer();
|
||||
VideoCompress.compressProgress$.subscribe(
|
||||
(event) {
|
||||
print('event: ${event}');
|
||||
},
|
||||
onDone: () {
|
||||
compressCompleter.complete();
|
||||
},
|
||||
onError: (e) {
|
||||
compressCompleter.completeError(e);
|
||||
},
|
||||
);
|
||||
await compressCompleter.future;
|
||||
}
|
||||
final mediaInfo = await VideoCompress.compressVideo(
|
||||
file.path,
|
||||
);
|
||||
|
||||
print('mediaInfo.filesize: ${mediaInfo.filesize / 1024}');
|
||||
|
||||
return mediaInfo;
|
||||
}
|
||||
|
||||
CircleAvatar _buildGiphyIcon() {
|
||||
if (kIsWeb) {
|
||||
return CircleAvatar(
|
||||
@@ -1571,7 +1556,8 @@ class MessageInputState extends State<MessageInput> {
|
||||
|
||||
if (file.size > _kMaxAttachmentSize) {
|
||||
if (attachmentType == 'video') {
|
||||
final mediaInfo = await _compressVideo(file);
|
||||
final mediaInfo = await CompressVideoService.instance
|
||||
.compressVideo(file.path, _kMaxAttachmentSize);
|
||||
file = PlatformFile(
|
||||
name: mediaInfo.title,
|
||||
size: mediaInfo.filesize,
|
||||
@@ -1800,23 +1786,11 @@ class MessageInputState extends State<MessageInput> {
|
||||
}
|
||||
|
||||
StreamSubscription _keyboardListener;
|
||||
Subscription _videoCompressSubscription;
|
||||
Completer _videoCompressCompleter = Completer();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
VideoCompress.compressProgress$.subscribe(
|
||||
(event) {},
|
||||
onDone: () {
|
||||
_videoCompressCompleter.complete();
|
||||
},
|
||||
onError: (e) {
|
||||
_videoCompressCompleter.completeError(e);
|
||||
},
|
||||
);
|
||||
|
||||
_focusNode = widget.focusNode ?? FocusNode();
|
||||
|
||||
_emojiNames = Emoji.all().map((e) => e.name);
|
||||
|
||||
Reference in New Issue
Block a user