compress videos
This commit is contained in:
@@ -185,26 +185,25 @@ class _ChannelListViewState extends State<ChannelListView>
|
|||||||
child = widget.emptyBuilder(context);
|
child = widget.emptyBuilder(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (channels.isEmpty && widget.emptyBuilder == null) {
|
if (channels.isEmpty && widget.emptyBuilder == null) {
|
||||||
child = LayoutBuilder(
|
child = LayoutBuilder(
|
||||||
builder: (context, viewportConstraints) {
|
builder: (context, viewportConstraints) {
|
||||||
return SingleChildScrollView(
|
return SingleChildScrollView(
|
||||||
physics: AlwaysScrollableScrollPhysics(),
|
physics: AlwaysScrollableScrollPhysics(),
|
||||||
child: Stack(
|
child: Stack(
|
||||||
children: [
|
children: [
|
||||||
ConstrainedBox(
|
ConstrainedBox(
|
||||||
constraints: BoxConstraints(
|
constraints: BoxConstraints(
|
||||||
minHeight: viewportConstraints.maxHeight,
|
minHeight: viewportConstraints.maxHeight,
|
||||||
),
|
),
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.all(8.0),
|
padding: const EdgeInsets.all(8.0),
|
||||||
child: StreamSvgIcon.message(
|
child: StreamSvgIcon.message(
|
||||||
size: 136,
|
size: 136,
|
||||||
color: Color(0xffDBDBDB),
|
color: Color(0xffDBDBDB),
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Padding(
|
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:mime/mime.dart';
|
||||||
import 'package:permission_handler/permission_handler.dart';
|
import 'package:permission_handler/permission_handler.dart';
|
||||||
import 'package:stream_chat/stream_chat.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/media_list_view.dart';
|
||||||
import 'package:stream_chat_flutter/src/message_list_view.dart';
|
import 'package:stream_chat_flutter/src/message_list_view.dart';
|
||||||
import 'package:stream_chat_flutter/src/stream_chat_theme.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 (file.size > _kMaxAttachmentSize) {
|
||||||
if (medium.mediaType == MediaType.video) {
|
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(
|
file = PlatformFile(
|
||||||
name: file.name,
|
name: file.name,
|
||||||
size: mediaInfo.filesize,
|
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() {
|
CircleAvatar _buildGiphyIcon() {
|
||||||
if (kIsWeb) {
|
if (kIsWeb) {
|
||||||
return CircleAvatar(
|
return CircleAvatar(
|
||||||
@@ -1571,7 +1556,8 @@ class MessageInputState extends State<MessageInput> {
|
|||||||
|
|
||||||
if (file.size > _kMaxAttachmentSize) {
|
if (file.size > _kMaxAttachmentSize) {
|
||||||
if (attachmentType == 'video') {
|
if (attachmentType == 'video') {
|
||||||
final mediaInfo = await _compressVideo(file);
|
final mediaInfo = await CompressVideoService.instance
|
||||||
|
.compressVideo(file.path, _kMaxAttachmentSize);
|
||||||
file = PlatformFile(
|
file = PlatformFile(
|
||||||
name: mediaInfo.title,
|
name: mediaInfo.title,
|
||||||
size: mediaInfo.filesize,
|
size: mediaInfo.filesize,
|
||||||
@@ -1800,23 +1786,11 @@ class MessageInputState extends State<MessageInput> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
StreamSubscription _keyboardListener;
|
StreamSubscription _keyboardListener;
|
||||||
Subscription _videoCompressSubscription;
|
|
||||||
Completer _videoCompressCompleter = Completer();
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
|
|
||||||
VideoCompress.compressProgress$.subscribe(
|
|
||||||
(event) {},
|
|
||||||
onDone: () {
|
|
||||||
_videoCompressCompleter.complete();
|
|
||||||
},
|
|
||||||
onError: (e) {
|
|
||||||
_videoCompressCompleter.completeError(e);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
_focusNode = widget.focusNode ?? FocusNode();
|
_focusNode = widget.focusNode ?? FocusNode();
|
||||||
|
|
||||||
_emojiNames = Emoji.all().map((e) => e.name);
|
_emojiNames = Emoji.all().map((e) => e.name);
|
||||||
|
|||||||
Reference in New Issue
Block a user