use lock in compress service
This commit is contained in:
@@ -1,19 +1,18 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
import 'package:synchronized/synchronized.dart';
|
||||||
import 'package:video_compress/video_compress.dart';
|
import 'package:video_compress/video_compress.dart';
|
||||||
|
|
||||||
class CompressVideoService {
|
class CompressVideoService {
|
||||||
static final CompressVideoService instance = CompressVideoService._();
|
static final CompressVideoService instance = CompressVideoService._();
|
||||||
|
final _lock = Lock();
|
||||||
CompressVideoService._();
|
CompressVideoService._();
|
||||||
|
|
||||||
Future<MediaInfo> compressVideo(String path) async {
|
Future<MediaInfo> compressVideo(String path) async {
|
||||||
MediaInfo mediaInfo;
|
print('VideoCompress.isCompressing: ${VideoCompress.isCompressing}');
|
||||||
while (VideoCompress.isCompressing) {
|
return _lock.synchronized(() {
|
||||||
await Future.delayed(Duration(seconds: 1));
|
return VideoCompress.compressVideo(
|
||||||
}
|
path,
|
||||||
mediaInfo = await VideoCompress.compressVideo(
|
);
|
||||||
path,
|
});
|
||||||
);
|
|
||||||
return mediaInfo;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -877,6 +877,11 @@ class MessageInputState extends State<MessageInput> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
setState(() {
|
||||||
|
_attachments.remove(attachment);
|
||||||
|
});
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
file = PlatformFile(
|
file = PlatformFile(
|
||||||
name: file.name,
|
name: file.name,
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ dependencies:
|
|||||||
permission_handler: ^5.0.1+1
|
permission_handler: ^5.0.1+1
|
||||||
transparent_image: ^1.0.0
|
transparent_image: ^1.0.0
|
||||||
ezanimation: ^0.4.1
|
ezanimation: ^0.4.1
|
||||||
|
synchronized: ^2.2.0+2
|
||||||
|
|
||||||
flutter:
|
flutter:
|
||||||
assets:
|
assets:
|
||||||
|
|||||||
Reference in New Issue
Block a user