diff --git a/example/.flutter-plugins-dependencies b/example/.flutter-plugins-dependencies index afab8a4e..2603b889 100644 --- a/example/.flutter-plugins-dependencies +++ b/example/.flutter-plugins-dependencies @@ -1 +1 @@ -{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"image_picker","path":"/Users/jonatasborges/flutter/.pub-cache/hosted/pub.dartlang.org/image_picker-0.7.4/","dependencies":[]},{"name":"video_compress","path":"/Users/jonatasborges/VideoCompress/","dependencies":[]},{"name":"video_player","path":"/Users/jonatasborges/flutter/.pub-cache/hosted/pub.dartlang.org/video_player-0.10.12+5/","dependencies":[]}],"android":[{"name":"flutter_plugin_android_lifecycle","path":"/Users/jonatasborges/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_plugin_android_lifecycle-2.0.1/","dependencies":[]},{"name":"image_picker","path":"/Users/jonatasborges/flutter/.pub-cache/hosted/pub.dartlang.org/image_picker-0.7.4/","dependencies":["flutter_plugin_android_lifecycle"]},{"name":"video_compress","path":"/Users/jonatasborges/VideoCompress/","dependencies":[]},{"name":"video_player","path":"/Users/jonatasborges/flutter/.pub-cache/hosted/pub.dartlang.org/video_player-0.10.12+5/","dependencies":[]}],"macos":[{"name":"file_selector_macos","path":"/Users/jonatasborges/flutter/.pub-cache/hosted/pub.dartlang.org/file_selector_macos-0.0.4/","dependencies":[]},{"name":"video_compress","path":"/Users/jonatasborges/VideoCompress/","dependencies":[]}],"linux":[],"windows":[],"web":[{"name":"file_selector_web","path":"/Users/jonatasborges/flutter/.pub-cache/hosted/pub.dartlang.org/file_selector_web-0.8.1/","dependencies":[]},{"name":"image_picker_for_web","path":"/Users/jonatasborges/flutter/.pub-cache/hosted/pub.dartlang.org/image_picker_for_web-2.0.0/","dependencies":[]},{"name":"video_player_web","path":"/Users/jonatasborges/flutter/.pub-cache/hosted/pub.dartlang.org/video_player_web-0.1.4+1/","dependencies":[]}]},"dependencyGraph":[{"name":"file_selector","dependencies":["file_selector_web"]},{"name":"file_selector_macos","dependencies":[]},{"name":"file_selector_web","dependencies":[]},{"name":"flutter_plugin_android_lifecycle","dependencies":[]},{"name":"image_picker","dependencies":["flutter_plugin_android_lifecycle","image_picker_for_web"]},{"name":"image_picker_for_web","dependencies":[]},{"name":"video_compress","dependencies":[]},{"name":"video_player","dependencies":["video_player_web"]},{"name":"video_player_web","dependencies":[]}],"date_created":"2021-03-31 10:22:40.807552","version":"2.0.3"} \ No newline at end of file +{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"image_picker","path":"/Users/abizanz/tools/flutter/.pub-cache/hosted/pub.dartlang.org/image_picker-0.7.4/","dependencies":[]},{"name":"video_compress","path":"/Users/abizanz/source/flutter-apps/VideoCompress/","dependencies":[]},{"name":"video_player","path":"/Users/abizanz/tools/flutter/.pub-cache/hosted/pub.dartlang.org/video_player-0.10.12+5/","dependencies":[]}],"android":[{"name":"flutter_plugin_android_lifecycle","path":"/Users/abizanz/tools/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_plugin_android_lifecycle-2.0.1/","dependencies":[]},{"name":"image_picker","path":"/Users/abizanz/tools/flutter/.pub-cache/hosted/pub.dartlang.org/image_picker-0.7.4/","dependencies":["flutter_plugin_android_lifecycle"]},{"name":"video_compress","path":"/Users/abizanz/source/flutter-apps/VideoCompress/","dependencies":[]},{"name":"video_player","path":"/Users/abizanz/tools/flutter/.pub-cache/hosted/pub.dartlang.org/video_player-0.10.12+5/","dependencies":[]}],"macos":[{"name":"file_selector_macos","path":"/Users/abizanz/tools/flutter/.pub-cache/hosted/pub.dartlang.org/file_selector_macos-0.0.4/","dependencies":[]},{"name":"video_compress","path":"/Users/abizanz/source/flutter-apps/VideoCompress/","dependencies":[]}],"linux":[],"windows":[],"web":[{"name":"file_selector_web","path":"/Users/abizanz/tools/flutter/.pub-cache/hosted/pub.dartlang.org/file_selector_web-0.8.1/","dependencies":[]},{"name":"image_picker_for_web","path":"/Users/abizanz/tools/flutter/.pub-cache/hosted/pub.dartlang.org/image_picker_for_web-2.0.0/","dependencies":[]},{"name":"video_player_web","path":"/Users/abizanz/tools/flutter/.pub-cache/hosted/pub.dartlang.org/video_player_web-0.1.4+1/","dependencies":[]}]},"dependencyGraph":[{"name":"file_selector","dependencies":["file_selector_web"]},{"name":"file_selector_macos","dependencies":[]},{"name":"file_selector_web","dependencies":[]},{"name":"flutter_plugin_android_lifecycle","dependencies":[]},{"name":"image_picker","dependencies":["flutter_plugin_android_lifecycle","image_picker_for_web"]},{"name":"image_picker_for_web","dependencies":[]},{"name":"video_compress","dependencies":[]},{"name":"video_player","dependencies":["video_player_web"]},{"name":"video_player_web","dependencies":[]}],"date_created":"2021-04-20 10:24:12.858575","version":"2.0.3"} \ No newline at end of file diff --git a/example/ios/Flutter/flutter_export_environment.sh b/example/ios/Flutter/flutter_export_environment.sh index 6a1c4dce..ca1d41bb 100755 --- a/example/ios/Flutter/flutter_export_environment.sh +++ b/example/ios/Flutter/flutter_export_environment.sh @@ -1,13 +1,14 @@ #!/bin/sh # This is a generated file; do not edit or check into version control. -export "FLUTTER_ROOT=/Users/jonatasborges/flutter" -export "FLUTTER_APPLICATION_PATH=/Users/jonatasborges/VideoCompress/example" -export "FLUTTER_TARGET=lib/main.dart" +export "FLUTTER_ROOT=/Users/abizanz/tools/flutter" +export "FLUTTER_APPLICATION_PATH=/Users/abizanz/source/flutter-apps/VideoCompress/example" +export "FLUTTER_TARGET=/Users/abizanz/source/flutter-apps/VideoCompress/example/lib/main.dart" export "FLUTTER_BUILD_DIR=build" export "SYMROOT=${SOURCE_ROOT}/../build/ios" export "FLUTTER_BUILD_NAME=1.0.0" export "FLUTTER_BUILD_NUMBER=1" +export "DART_DEFINES=flutter.inspector.structuredErrors%3Dtrue" export "DART_OBFUSCATION=false" -export "TRACK_WIDGET_CREATION=false" +export "TRACK_WIDGET_CREATION=true" export "TREE_SHAKE_ICONS=false" -export "PACKAGE_CONFIG=.packages" +export "PACKAGE_CONFIG=/Users/abizanz/source/flutter-apps/VideoCompress/example/.dart_tool/package_config.json" diff --git a/example/ios/Runner.xcodeproj/project.pbxproj b/example/ios/Runner.xcodeproj/project.pbxproj index 7e09cfcc..b9539c6c 100644 --- a/example/ios/Runner.xcodeproj/project.pbxproj +++ b/example/ios/Runner.xcodeproj/project.pbxproj @@ -10,11 +10,7 @@ 0910DC4AAB319CB550545C57 /* Pods_Runner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EE7CD6F4DADA18DACEE24635 /* Pods_Runner.framework */; }; 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; }; 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; }; - 3B80C3941E831B6300D905FE /* App.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; }; - 3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74858FAE1ED2DC5600515810 /* AppDelegate.swift */; }; - 9705A1C61CF904A100538489 /* Flutter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9740EEBA1CF902C7004384FC /* Flutter.framework */; }; - 9705A1C71CF904A300538489 /* Flutter.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 9740EEBA1CF902C7004384FC /* Flutter.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; }; 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; }; 97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */; }; @@ -27,8 +23,6 @@ dstPath = ""; dstSubfolderSpec = 10; files = ( - 3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */, - 9705A1C71CF904A300538489 /* Flutter.framework in Embed Frameworks */, ); name = "Embed Frameworks"; runOnlyForDeploymentPostprocessing = 0; @@ -41,13 +35,11 @@ 2F308078F8D8AEC04C19831E /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = ""; }; 39702881BB56947DF75349A3 /* Pods-Runner.profile.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.profile.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig"; sourceTree = ""; }; 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = ""; }; - 3B80C3931E831B6300D905FE /* App.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = App.framework; path = Flutter/App.framework; sourceTree = ""; }; 74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Runner-Bridging-Header.h"; sourceTree = ""; }; 74858FAE1ED2DC5600515810 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = ""; }; 9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = ""; }; 9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = ""; }; - 9740EEBA1CF902C7004384FC /* Flutter.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Flutter.framework; path = Flutter/Flutter.framework; sourceTree = ""; }; 97C146EE1CF9000F007C117D /* Runner.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Runner.app; sourceTree = BUILT_PRODUCTS_DIR; }; 97C146FB1CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 97C146FD1CF9000F007C117D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; @@ -62,8 +54,6 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 9705A1C61CF904A100538489 /* Flutter.framework in Frameworks */, - 3B80C3941E831B6300D905FE /* App.framework in Frameworks */, 0910DC4AAB319CB550545C57 /* Pods_Runner.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -92,9 +82,7 @@ 9740EEB11CF90186004384FC /* Flutter */ = { isa = PBXGroup; children = ( - 3B80C3931E831B6300D905FE /* App.framework */, 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */, - 9740EEBA1CF902C7004384FC /* Flutter.framework */, 9740EEB21CF90195004384FC /* Debug.xcconfig */, 7AFA3C8E1D35360C0083082E /* Release.xcconfig */, 9740EEB31CF90195004384FC /* Generated.xcconfig */, @@ -180,6 +168,7 @@ TargetAttributes = { 97C146ED1CF9000F007C117D = { CreatedOnToolsVersion = 7.3.1; + DevelopmentTeam = 4S4XXF7A69; LastSwiftMigration = 1020; }; }; @@ -229,7 +218,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" thin"; + shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" embed_and_thin"; }; 600D16CF5758BF2E958F6D05 /* [CP] Embed Pods Frameworks */ = { isa = PBXShellScriptBuildPhase; @@ -238,18 +227,14 @@ ); inputPaths = ( "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh", - "${PODS_ROOT}/../.symlinks/flutter/ios-release/Flutter.framework", - "${BUILT_PRODUCTS_DIR}/Regift/Regift.framework", - "${BUILT_PRODUCTS_DIR}/video_compress/video_compress.framework", "${BUILT_PRODUCTS_DIR}/image_picker/image_picker.framework", + "${BUILT_PRODUCTS_DIR}/video_compress/video_compress.framework", "${BUILT_PRODUCTS_DIR}/video_player/video_player.framework", ); name = "[CP] Embed Pods Frameworks"; outputPaths = ( - "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Flutter.framework", - "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Regift.framework", - "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/video_compress.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/image_picker.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/video_compress.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/video_player.framework", ); runOnlyForDeploymentPostprocessing = 0; @@ -325,7 +310,6 @@ /* Begin XCBuildConfiguration section */ 249021D3217E4FDB00AE95B9 /* Profile */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; @@ -381,6 +365,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; + DEVELOPMENT_TEAM = 4S4XXF7A69; ENABLE_BITCODE = NO; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -401,7 +386,6 @@ }; 97C147031CF9000F007C117D /* Debug */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; @@ -459,7 +443,6 @@ }; 97C147041CF9000F007C117D /* Release */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; @@ -517,7 +500,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; - DEVELOPMENT_TEAM = BZV32XF67X; + DEVELOPMENT_TEAM = 4S4XXF7A69; ENABLE_BITCODE = NO; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -545,7 +528,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; - DEVELOPMENT_TEAM = BZV32XF67X; + DEVELOPMENT_TEAM = 4S4XXF7A69; ENABLE_BITCODE = NO; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", diff --git a/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata index 1d526a16..919434a6 100644 --- a/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata +++ b/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -2,6 +2,6 @@ + location = "self:"> diff --git a/example/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings b/example/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings deleted file mode 100644 index 949b6789..00000000 --- a/example/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings +++ /dev/null @@ -1,8 +0,0 @@ - - - - - BuildSystemType - Original - - diff --git a/example/ios/Runner/Info.plist b/example/ios/Runner/Info.plist index 173c1230..7946d756 100644 --- a/example/ios/Runner/Info.plist +++ b/example/ios/Runner/Info.plist @@ -22,6 +22,17 @@ $(FLUTTER_BUILD_NUMBER) LSRequiresIPhoneOS + NSAppTransportSecurity + + NSAllowsArbitraryLoads + + + NSCameraUsageDescription + Example usage description + NSMicrophoneUsageDescription + Example usage description + NSPhotoLibraryUsageDescription + Example usage description UILaunchStoryboardName LaunchScreen UIMainStoryboardFile @@ -41,16 +52,5 @@ UIViewControllerBasedStatusBarAppearance - NSPhotoLibraryUsageDescription - Example usage description - NSCameraUsageDescription - Example usage description - NSMicrophoneUsageDescription - Example usage description - NSAppTransportSecurity - - NSAllowsArbitraryLoads - - diff --git a/example/lib/main.dart b/example/lib/main.dart index 4db2adc5..816fdb25 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -4,6 +4,8 @@ import 'package:video_compress/video_compress.dart'; import 'package:file_selector/file_selector.dart'; import 'dart:io'; +import 'package:video_player/video_player.dart'; + void main() { runApp(MyApp()); } @@ -31,7 +33,12 @@ class MyHomePage extends StatefulWidget { } class _MyHomePageState extends State { - String _counter = "video"; + String _progress="0"; + @override + void initState() { + super.initState(); + + } @override Widget build(BuildContext context) { @@ -43,13 +50,8 @@ class _MyHomePageState extends State { child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ - Text( - 'You have pushed the button this many times:', - ), - Text( - '$_counter', - style: Theme.of(context).textTheme.headline4, - ), + Text('Progress $_progress', style: Theme.of(context).textTheme.headline4,), + InkWell( child: Icon( Icons.cancel, @@ -63,35 +65,161 @@ class _MyHomePageState extends State { ), floatingActionButton: FloatingActionButton( onPressed: () async { + var startTime = DateTime.now(); var file; + var originalSize = 0; if (Platform.isMacOS) { final typeGroup = XTypeGroup(label: 'videos', extensions: ['mov', 'mp4']); file = await openFile(acceptedTypeGroups: [typeGroup]); + } else { final picker = ImagePicker(); PickedFile pickedFile = await picker.getVideo(source: ImageSource.gallery); file = File(pickedFile.path); + originalSize = await file.length(); } if (file == null) { return; } await VideoCompress.setLogLevel(0); - final info = await VideoCompress.compressVideo( + final infoFuture = VideoCompress.compressVideo( file.path, - quality: VideoQuality.MediumQuality, + quality: VideoQuality.LowQuality, deleteOrigin: false, includeAudio: true, ); + var _subscription = + VideoCompress.compressProgress$.subscribe((progress) { + setState(() { + _progress = '${progress.toInt().toString()}%'; + }); + }); + final info = await infoFuture; + _subscription.unsubscribe(); + var conversionTime = DateTimeRange(start: startTime, end: DateTime.now()); + setState(() { + _progress = "0"; + }); print(info.path); - if (info != null) { - setState(() { - _counter = info.path; - }); - } + Navigator.of(context).push(MaterialPageRoute(builder: (_) => + VideoPlayerScreen(info: info,originalSize: originalSize, duration: conversionTime ))); + }, - tooltip: 'Increment', child: Icon(Icons.add), ), ); } } + +class VideoPlayerScreen extends StatefulWidget { + final MediaInfo info; + final int originalSize; + final DateTimeRange duration; + VideoPlayerScreen({Key key, this.info, this.originalSize, this.duration}) : super(key: key); + + @override + _VideoPlayerScreenState createState() => _VideoPlayerScreenState(); +} + +class _VideoPlayerScreenState extends State { + VideoPlayerController _controller; + Future _initializeVideoPlayerFuture; + + @override + void initState() { + // Create and store the VideoPlayerController. The VideoPlayerController + // offers several different constructors to play videos from assets, files, + // or the internet. + _controller = VideoPlayerController.file( + File(widget.info.path) + ); + + // Initialize the controller and store the Future for later use. + _initializeVideoPlayerFuture = _controller.initialize(); + + // Use the controller to loop the video. + _controller.setLooping(true); + + super.initState(); + } + + @override + void dispose() { + // Ensure disposing of the VideoPlayerController to free up resources. + _controller.dispose(); + + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: Text('Compressed Video'), + ), + // Use a FutureBuilder to display a loading spinner while waiting for the + // VideoPlayerController to finish initializing. + body: FutureBuilder( + future: _initializeVideoPlayerFuture, + builder: (context, snapshot) { + if (snapshot.connectionState == ConnectionState.done) { + // If the VideoPlayerController has finished initialization, use + // the data it provides to limit the aspect ratio of the video. + return Stack( + children: [ + AspectRatio( + aspectRatio: _controller.value.aspectRatio, + // Use the VideoPlayer widget to display the video. + child: VideoPlayer(_controller), + ), + Column( + mainAxisAlignment: MainAxisAlignment.end, + children: [ + Container( + color: Color.fromRGBO(100, 100, 100, 0.5), + width: MediaQuery.of(context).size.width, + height: 200, + child: Column( + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Text('video length ${(widget.info.duration/1000).toInt()} Seconds'), + Text('Converted size: ${(widget.info.filesize/1000000).toString()}', style: TextStyle(fontWeight: FontWeight.bold),), + Text('original size: ${(widget.originalSize/1000000).toString()}', style: TextStyle(fontWeight: FontWeight.bold),), + Text('Conversion duration: ${(widget.duration.duration.inSeconds).toString()}', style: TextStyle(fontWeight: FontWeight.bold),), + + ], + ), + ), + ], + ) + ], + ); + } else { + // If the VideoPlayerController is still initializing, show a + // loading spinner. + return Center(child: CircularProgressIndicator()); + } + }, + ), + floatingActionButton: FloatingActionButton( + onPressed: () { + // Wrap the play or pause in a call to `setState`. This ensures the + // correct icon is shown. + setState(() { + // If the video is playing, pause it. + if (_controller.value.isPlaying) { + _controller.pause(); + } else { + // If the video is paused, play it. + _controller.play(); + } + }); + }, + // Display the correct icon depending on the state of the player. + child: Icon( + _controller.value.isPlaying ? Icons.pause : Icons.play_arrow, + ), + ), // This trailing comma makes auto-formatting nicer for build methods. + ); + } +} diff --git a/ios/Classes/SwiftVideoCompressPlugin.swift b/ios/Classes/SwiftVideoCompressPlugin.swift index ad95ed5c..44f5db31 100644 --- a/ios/Classes/SwiftVideoCompressPlugin.swift +++ b/ios/Classes/SwiftVideoCompressPlugin.swift @@ -174,9 +174,9 @@ public class SwiftVideoCompressPlugin: NSObject, FlutterPlugin { let sourceVideoAsset = avController.getVideoAsset(sourceVideoUrl) let sourceVideoTrack = avController.getTrack(sourceVideoAsset) - + let fileName = ProcessInfo.processInfo.globallyUniqueString let compressionUrl = - Utility.getPathUrl("\(Utility.basePath())/\(Utility.getFileName(path)).\(sourceVideoType)") + Utility.getPathUrl("\(Utility.basePath())/\(fileName).\(sourceVideoType)") let timescale = sourceVideoAsset.duration.timescale let minStartTime = Double(startTime ?? 0) @@ -213,15 +213,19 @@ public class SwiftVideoCompressPlugin: NSObject, FlutterPlugin { let timer = Timer.scheduledTimer(timeInterval: 0.1, target: self, selector: #selector(self.updateProgress), userInfo: exporter, repeats: true) - + NSLog("Exporting starting") exporter.exportAsynchronously(completionHandler: { - if(self.stopCommand) { - timer.invalidate() - self.stopCommand = false - var json = self.getMediaInfoJson(path) - json["isCancel"] = true - let jsonString = Utility.keyValueToJson(json) - return result(jsonString) + + switch exporter.status { + case .failed: + let description = "\(String(describing: exporter.error))" + NSLog (description); + case .cancelled: + NSLog("Export canceled") + case .completed: + NSLog("Successful!") + default: + NSLog("default case") } if deleteOrigin { timer.invalidate() @@ -241,7 +245,7 @@ public class SwiftVideoCompressPlugin: NSObject, FlutterPlugin { json["isCancel"] = false let jsonString = Utility.keyValueToJson(json) result(jsonString) - }) + }) } private func cancelCompression(_ result: FlutterResult) { diff --git a/lib/src/video_compress/video_compressor.dart b/lib/src/video_compress/video_compressor.dart index d248021a..465fe03c 100644 --- a/lib/src/video_compress/video_compressor.dart +++ b/lib/src/video_compress/video_compressor.dart @@ -122,6 +122,7 @@ extension Compress on IVideoCompress { int? startTime, int? duration, bool? includeAudio, + required String into, int frameRate = 30, }) async { if (isCompressing) { @@ -144,6 +145,7 @@ extension Compress on IVideoCompress { 'duration': duration, 'includeAudio': includeAudio, 'frameRate': frameRate, + 'into': into }); // ignore: invalid_use_of_protected_member