light_compressor icon indicating copy to clipboard operation
light_compressor copied to clipboard

Compress Video with Worker Manager

Open singhmukesh2023 opened this issue 1 year ago • 0 comments

I need to compress video before uploading on server. I had implement video compress code with Worker Manager with await. But it terminate at video compress line.

Please suggest that how to implement with with Worker Manager. Worker Manager https://pub.dev/packages/workmanager

With Worker Manager

   String? compressFilePath =
              await compressVideo(attachment.localfilePath?.path ?? "");

Video Compress Code

  Future<String?> compressVideo(String filePath) async {
    try {    
      LightCompressor lightCompressor = LightCompressor();
      final String videoName =
          'PINEWS_${DateTime.now().millisecondsSinceEpoch}.mp4';      
      final Result response = await lightCompressor.compressVideo(
        path: filePath,
        videoQuality: VideoQuality.medium,
        isMinBitrateCheckEnabled: false,
        video: Video(videoName: videoName),
        android: AndroidConfig(isSharedStorage: true, saveAt: SaveAt.Movies),
        ios: IOSConfig(saveInGallery: false),
      );
      if (response is OnSuccess) {          
        return response.destinationPath;
      } else if (response is OnFailure) {           
      } else if (response is OnCancelled) {        
      }
      return null;
    } catch (error) {
         return null;
    }
  }

singhmukesh2023 avatar Oct 07 '24 10:10 singhmukesh2023