Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed progress events #37

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Works on ANDROID and IOS.
## Video compression

```dart
MediaInfo mediaInfo = await VideoCompress.compressVideo(
MediaInfo mediaInfo = await VideoCompress().compressVideo(
path,
quality: VideoQuality.DefaultQuality,
deleteOrigin: false, // It's false by default
Expand All @@ -24,7 +24,7 @@ MediaInfo mediaInfo = await VideoCompress.compressVideo(

## Check compress state
```dart
VideoQuality.isCompressing
VideoCompress().isCompressing
```
<!-- ## Cancel compression
```dart
Expand All @@ -33,7 +33,7 @@ await videoCompress.cancelCompression()

## Get memory thumbnail from VideoPath
```dart
final uint8list = await VideoCompress.getByteThumbnail(
final uint8list = await VideoCompress().getByteThumbnail(
videopath,
quality: 50, // default(100)
position: -1 // default(-1)
Expand All @@ -42,7 +42,7 @@ final uint8list = await VideoCompress.getByteThumbnail(

## Get File thumbnail from VideoPath
```dart
final thumbnailFile = await VideoCompress.getFileThumbnail(
final thumbnailFile = await VideoCompress().getFileThumbnail(
videopath,
quality: 50, // default(100)
position: -1 // default(-1)
Expand All @@ -52,7 +52,7 @@ final thumbnailFile = await VideoCompress.getFileThumbnail(
## Get media information

```dart
final info = await VideoCompress.getMediaInfo(videopath);
final info = await VideoCompress().getMediaInfo(videopath);

```

Expand All @@ -72,8 +72,7 @@ class _Compress extends State<Compress> {
@override
void initState() {
super.initState();
_subscription =
VideoCompress.compressProgress$.subscribe((progress) {
_subscription = VideoCompress().compressProgress$.subscribe((progress) {
debugPrint('progress: $progress');
});
}
Expand Down
26 changes: 13 additions & 13 deletions lib/src/video_compressor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,28 @@ class VideoCompress {
_channel.setMethodCallHandler(_progresCallback);
}

static const _channel = const MethodChannel('video_compress');
final _channel = const MethodChannel('video_compress');

/// Check compress state
static bool get isCompressing => _isCompressing;
bool get isCompressing => _isCompressing;

static bool _isCompressing = false;
bool _isCompressing = false;

Future<void> _progresCallback(MethodCall call) async {
switch (call.method) {
case 'updateProgress':
final progress = double.tryParse(call.arguments.toString());
if (progress != null) compressProgress$.next(progress);
break;
default:
print('Progress callback: ${call.method}');
}
}

/// Subscribe the compress progress
static ObservableBuilder<double> compressProgress$ =
ObservableBuilder<double>();
ObservableBuilder<double> compressProgress$ = ObservableBuilder<double>();

static Future<T> _invoke<T>(String name,
[Map<String, dynamic> params]) async {
Future<T> _invoke<T>(String name, [Map<String, dynamic> params]) async {
T result;
try {
result = params != null
Expand All @@ -58,7 +58,7 @@ class VideoCompress {
/// getByteThumbnail return [Future<Uint8List>],
/// quality can be controlled by [quality] from 1 to 100,
/// select the position unit in the video by [position] is seconds
static Future<Uint8List> getByteThumbnail(
Future<Uint8List> getByteThumbnail(
String path, {
int quality = 100,
int position = -1,
Expand All @@ -76,7 +76,7 @@ class VideoCompress {
/// getFileThumbnail return [Future<File>]
/// quality can be controlled by [quality] from 1 to 100,
/// select the position unit in the video by [position] is seconds
static Future<File> getFileThumbnail(
Future<File> getFileThumbnail(
String path, {
int quality = 100,
int position = -1,
Expand Down Expand Up @@ -104,7 +104,7 @@ class VideoCompress {
/// final info = await _flutterVideoCompress.getMediaInfo(file.path);
/// debugPrint(info.toJson());
/// ```
static Future<MediaInfo> getMediaInfo(String path) async {
Future<MediaInfo> getMediaInfo(String path) async {
assert(path != null);
final jsonStr = await _invoke<String>('getMediaInfo', {'path': path});
final jsonMap = json.decode(jsonStr);
Expand All @@ -126,7 +126,7 @@ class VideoCompress {
/// );
/// debugPrint(info.toJson());
/// ```
static Future<MediaInfo> compressVideo(
Future<MediaInfo> compressVideo(
String path, {
VideoQuality quality = VideoQuality.DefaultQuality,
bool deleteOrigin = false,
Expand Down Expand Up @@ -162,13 +162,13 @@ class VideoCompress {

/// stop compressing the file that is currently being compressed.
/// If there is no compression process, nothing will happen.
static Future<void> cancelCompression() async {
Future<void> cancelCompression() async {
await _invoke<void>('cancelCompression');
}

/// delete the cache folder, please do not put other things
/// in the folder of this plugin, it will be cleared
static Future<bool> deleteAllCache() async {
Future<bool> deleteAllCache() async {
return await _invoke<bool>('deleteAllCache');
}
}
Expand Down