flutter_video_compress icon indicating copy to clipboard operation
flutter_video_compress copied to clipboard

[Bug] App crashes when compressing multiple videos using a for loop

Open Loopex2019 opened this issue 5 years ago • 2 comments

Hi i want to compress a List of videos . So i tried to do this using a for in loop . But when compressing starts the app crashes . With one video only it works but with multiple videos it crashes . I use this with firebase storage . Here is my code :

for (File mediaFile in mediaFiles) {
        final StorageReference _storageRef = FirebaseStorage.instance.ref();
        String _mediaId = Uuid().v4();
        final File _media = mediaFile.path.endsWith('.mp4')
            ? await compressVideo(mediaFile)
            : await compressImage(_mediaId, mediaFile);
        // Uploads user profile image
        final StorageUploadTask _uploadTask = _storageRef
            .child(
              !mediaFile.path.endsWith('.mp4')
                  ? '$path/$_mediaId.jpg'
                  : '$path/$_mediaId.mp4',
            )
            .putFile(_media);
        final StorageTaskSnapshot _storageSnap = await _uploadTask.onComplete;
        final String _downloadUrl = await _storageSnap.ref.getDownloadURL();
        _mediaUrls.add(_downloadUrl);
      }
      return _mediaUrls;
    }

And here is my video compression method :

static Future<File> compressVideo(File video) async {
    final FlutterVideoCompress _videoCompress = FlutterVideoCompress();
    final MediaInfo _compressedVideo = await _videoCompress.compressVideo(
      video.path,
      includeAudio: true,
    );
    return _compressedVideo.file;
  }

Loopex2019 avatar Jun 03 '20 08:06 Loopex2019

Any help

Loopex2019 avatar Jun 03 '20 20:06 Loopex2019

same issues don't know how to solve it

duongtruong12 avatar Jun 12 '20 10:06 duongtruong12