light_compressor
light_compressor copied to clipboard
Compression on Android 13 and other versions not working after authorization
I have an OPPO A16s phone with Android 13
I added in my manifest file the permissions below:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"
android:maxSdkVersion="32"/>
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="28"
tools:ignore="ScopedStorage" />
Here's a code snippet I used:
Future
final FilePickerResult? result = await FilePicker.platform.pickFiles(
type: FileType.video,
);
finalPlatformFile? file = result?.files.first;
if (file == null) {
return;
}
_filePath = file.path;
setState(() {
_failureMessage = null;
});
final String videoName =
'MyVideo-${DateTime.now().millisecondsSinceEpoch}.mp4';
final Stopwatch stopwatch = Stopwatch()..start();
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),
);
stopwatch.stop();
final Duration duration =
Duration(milliseconds: stopwatch.elapsedMilliseconds);
_duration = duration.inSeconds;
if (response is OnSuccess) {
setState(() {
_desFile = response.destinationPath;
_displayedFile = _desFile;
_isVideoCompressed = true;
});
print("Old path: $_filePath");
print("new path compressed: ${response.destinationPath}");
} else if (response is OnFailure) {
setState(() {
_failureMessage = response.message;
});
} else if (response is OnCancelled) {
print(response.isCancelled);
}
} When I click on FilePicker, a dialog box appears asking for access to images and videos, as long as I do not accept the permission, the compression works. If only I accept the permission, the compression no longer works.
Under Android 13, I see this on the console output: Caching from URI: content://media/picker/0/com.android.providers.media.photopicker/media/1000077196 D/FilePickerUtils(4441): File loaded and cached at:/data/user/0/com.lecteur.video/cache/file_picker/1000077196.mp4 D/FilePickerDelegate(4441): [MultiFilePick] File #0 - URI: /picker/0/com.android.providers.media.photopicker/media/1000077196
Under Android 8.1.0, console output: Caching from URI: content://com.android.providers.media.documents/document/video%3A14815 File loaded and cached at:/data/user/0/com.lecteur.video/cache/file_picker/VID-20231209-WA0085.mp4 D/FilePickerDelegate(18106): File path:[com.mr.flutter.plugin.filepicker.FileInfo@c947eb8]
I also found this problem, it exists on both android 13 and 14, have you solved it?
J'ai également trouvé ce problème, il existe à la fois sur Android 13 et 14, l'avez-vous résolu ?
I didn't solve the permission problem, but I found another solution at the moment, if we don't specify the location, the compressed file is in the application cache, so I just delete the compressed file after uploading the file to the database. If your case is that the compressed file is moved to shared memory, in this case you need to resolve the authorization problem.