We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Video compression can not get compression progress
Android
import 'dart:async'; import 'dart:io';
import 'package:flutter/material.dart'; import 'package:flutter/widgets.dart'; import 'package:flutter_video_compress/flutter_video_compress.dart'; import 'package:image_pickers/image_pickers.dart';
class TestVideoPage extends StatefulWidget {
@OverRide _TestVideoPageState createState() => _TestVideoPageState(); }
class _TestVideoPageState extends State {
final _flutterVideoCompress = FlutterVideoCompress(); Subscription _subscription;
Image _thumbnailFileImage; Image _gifFileImage;
MediaInfo _originalVideoInfo = MediaInfo(path: ''); MediaInfo _compressedVideoInfo = MediaInfo(path: ''); String _taskName; double _progressState = 0;
final _loadingStreamCtrl = StreamController.broadcast();
@OverRide void initState() { // TODO: implement initState super.initState(); _subscription = _flutterVideoCompress.compressProgress$.subscribe((progress) { debugPrint("progress----" + progress.toString()); setState(() { _progressState = progress; }); }); }
@OverRide void dispose() { super.dispose(); _subscription.unsubscribe(); _loadingStreamCtrl.close(); }
Future runFlutterVideoCompressMethods(String videoFile) async { _loadingStreamCtrl.sink.add(true);
var _startDateTime = DateTime.now(); print('[Compressing Video] start'); _taskName = '[Compressing Video]'; final compressedVideoInfo = await _flutterVideoCompress.compressVideo( videoFile, quality: VideoQuality.DefaultQuality, deleteOrigin: false, ); _taskName = null; print( '[Compressing Video] done! ${DateTime .now() .difference(_startDateTime) .inSeconds}s'); _startDateTime = DateTime.now(); print('[Getting Thumbnail File] start'); final thumbnailFile = await _flutterVideoCompress .getThumbnailWithFile(videoFile, quality: 50); print( '[Getting Thumbnail File] done! ${DateTime .now() .difference(_startDateTime) .inSeconds}s'); _startDateTime = DateTime.now(); print('[Getting Gif File] start'); _taskName = '[Getting Gif File]'; final gifFile = await _flutterVideoCompress .convertVideoToGif(videoFile, startTime: 0, duration: 5); print( '[Getting Gif File] done! ${DateTime .now() .difference(_startDateTime) .inSeconds}s'); _taskName = null; final videoInfo = await _flutterVideoCompress.getMediaInfo(videoFile); setState(() { _thumbnailFileImage = Image.file(thumbnailFile); _gifFileImage = Image.file(gifFile); _originalVideoInfo = videoInfo; _compressedVideoInfo = compressedVideoInfo; }); _loadingStreamCtrl.sink.add(false);
}
@OverRide Widget build(BuildContext context) { return Scaffold( body: Center( child: OutlinedButton( onPressed: () async { List _listVideoPaths = await ImagePickers.pickerPaths( galleryMode: GalleryMode.video, selectCount: 1, ); runFlutterVideoCompressMethods(_listVideoPaths[0].path); }, child: Text("选择视频"), ), ), ); } }
Expect description of the solution
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Description
Video compression can not get compression progress
Platform
Android
Code Example (if has)
import 'dart:async';
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_video_compress/flutter_video_compress.dart';
import 'package:image_pickers/image_pickers.dart';
class TestVideoPage extends StatefulWidget {
@OverRide
_TestVideoPageState createState() => _TestVideoPageState();
}
class _TestVideoPageState extends State {
final _flutterVideoCompress = FlutterVideoCompress();
Subscription _subscription;
Image _thumbnailFileImage;
Image _gifFileImage;
MediaInfo _originalVideoInfo = MediaInfo(path: '');
MediaInfo _compressedVideoInfo = MediaInfo(path: '');
String _taskName;
double _progressState = 0;
final _loadingStreamCtrl = StreamController.broadcast();
@OverRide
void initState() {
// TODO: implement initState
super.initState();
_subscription =
_flutterVideoCompress.compressProgress$.subscribe((progress) {
debugPrint("progress----" + progress.toString());
setState(() {
_progressState = progress;
});
});
}
@OverRide
void dispose() {
super.dispose();
_subscription.unsubscribe();
_loadingStreamCtrl.close();
}
Future runFlutterVideoCompressMethods(String videoFile) async {
_loadingStreamCtrl.sink.add(true);
}
@OverRide
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: OutlinedButton(
onPressed: () async {
List _listVideoPaths = await ImagePickers.pickerPaths(
galleryMode: GalleryMode.video,
selectCount: 1,
);
runFlutterVideoCompressMethods(_listVideoPaths[0].path);
},
child: Text("选择视频"),
),
),
);
}
}
Expected solution
Expect description of the solution
The text was updated successfully, but these errors were encountered: