AbedElazizShe / light_compressor

A powerful and easy-to-use video compression plugin for Flutter.
MIT License
59 stars 34 forks source link

Do not save the video in the gallery #10

Closed NaosFr closed 3 years ago

NaosFr commented 3 years ago

Hello, any idea how to not save the video in the phone gallery?

my code :

var file;
final tmpDir = await getTemporaryDirectory();

 final Map<String, dynamic> response = await LightCompressor.compressVideo(
          path: _attachement.path,
          destinationPath: '${tmpDir.path}/${DateTime.now().millisecondsSinceEpoch}.mp4',
          videoQuality: VideoQuality.high,
          isMinBitRateEnabled: false,
          keepOriginalResolution: false,
);

if (response['onSuccess'] != null) {
          file = File(response['onSuccess']);
} else if (response['onFailure'] != null) {

 } else if (response['onCancelled'] != null) {

}

if (file.existsSync()) {
          file.deleteSync();
}

thx for your time 😇

ghost commented 3 years ago

Same issue for me on iOS only. Write a copy of the compressed vidéo in the gallery.

final Map<String, dynamic>? response = await LightCompressor.compressVideo(
    path: _filePath!,
    destinationPath: _desFile,
    videoQuality: VideoQuality.high,
    isMinBitRateEnabled: false,
    keepOriginalResolution: false
  );
NaosFr commented 3 years ago

The problem is in the file "SwiftLightCompressorPlugin.swift"

Just remove:

DispatchQueue.main.async {
   PHPhotoLibrary.shared().performChanges({
     PHAssetChangeRequest.creationRequestForAssetFromVideo(atFileURL: path)
  })
 }

Maybe create an option 😎

ghost commented 3 years ago

It works like a charm. I hope it will be a fixed for futures versions. Merci Nicolas ca m'a fait gagner beaucoup de temps.

AbedElazizShe commented 3 years ago

Thank you for opening the issue and the suggestion to fix it, I added a bool iosSaveToGallery to avoid saving, you can just pass it with false. Please use version 1.0.3.

CyriDev commented 3 years ago

Thank you !