Created with <3 with dartpad.dev.
Created
July 10, 2023 15:08
-
-
Save stephanedeluca/4276d50f76d6a91b9173910d417e5a11 to your computer and use it in GitHub Desktop.
Video compression from within isolate issue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:isolate'; | |
import 'package:flutter/material.dart'; | |
import 'package:video_compress/video_compress.dart'; | |
const Color darkBlue = Color.fromARGB(255, 18, 32, 47); | |
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
theme:ThemeData( | |
useMaterial3: true, | |
//colorScheme: Colors.red, | |
), | |
debugShowCheckedModeBanner: false, | |
home: const Scaffold( | |
body: Center( | |
child: Column( | |
mainAxisSize: MainAxisSize.min, | |
children: [ | |
Text("Hello 👋🏻"), | |
Text("to compression in isolate"), | |
ElevatedButton( | |
onPressed: ()=> runVideoCompressionFromIsolate(), | |
child: const Text("RUN ISOLATE"), | |
) | |
]), | |
), | |
), | |
); | |
} | |
} | |
/// the code to run the compression from within the isolate | |
Future<void> runVideoCompressionFromIsolate () async { | |
final isolate = await Isolate.spawn<int>( | |
longTaskForIsolate, | |
7, | |
errorsAreFatal: true, // uncaught errors will terminate the isolate | |
debugName: 'longTaskVideoCompressionForIsolate', // name in debuggers and logging | |
); | |
await Future<void>.delayed(const Duration(seconds: 20)); | |
isolate.kill(); // Kill the isolate. | |
} | |
/// The entry point of the our isolate. | |
void longTaskVideoCompressionForIsolate(int payload) { | |
try { | |
// == Subscribe to progress | |
final _subscription = VideoCompress.compressProgress$.subscribe((progress) { | |
debugPrint('progress: $progress'); | |
}); | |
} | |
catch(e) { | |
debugPrint("Error while subscribing to video compressing"); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment