Fix MP4 videos saving result in 3GP on Android API <=28
Fixed the issue that the video format changes to 3gp when saving mp4 videos to the album on Android 9
Could you provide a test case in which saving 3gp will fail? Your changes don't tell the idea and why it will fix the issue well.
pubspec.yaml
photo_manager: ^3.3.0 photo_manager_image_provider: ^2.1.1
use my code
device:
Redmi Note5 android 9 MI 8 Lite android 9 MEIZU Note9 android 9
It is still unclear why the PR fixes the issue. Could you provide a minimal reproducible example?
example code
var appCacheDir = await getApplicationCacheDirectory();
String filePath = '${appCacheDir.path}/aaa.mp4';
File result = File(filePath);
var entity = await PhotoManager.editor.saveVideo(
result,
title: path.basename(result.path),
);
print('assetEntity===${entity!.title}===${await entity.file}');
On Android 9, the source file is mp4 and converted to 3gp format through saveVideo
Is this happening on all videos or just one specific video? Could you file an issue to summarize all the details? And provide a minimal runnable example so we can run to reproduce.
All videos on android9
demo: https://github.com/yishangfei/test1
https://github.com/user-attachments/assets/64cb697d-a3a2-4453-8726-b0e84bf29ba8
I added it in line 455 according to your latest code.
Still working on this?
now there is no problem. I only modified the version below Android 10. It’s just that the timestamp needs to be used when saving. If the original name is used a second time, the entity returned by PhotoManager.editor.saveVideo will be null.
If the original name is used a second time, the entity returned by PhotoManager.editor.saveVideo will be null.
We need to figure out why.
Also please do another rebase on the latest changes and remove unnecessary changes.
The automatic renaming function (for example, video (1).mp4) is implemented in Android 11 and above. In earlier versions, if you repeat cr.insert in the insertUri method, an exception will be thrown. "Cannot insert the new asset."
val uri = cr.insert(contentUri, values) ?: throw RuntimeException("Cannot insert the new asset.")
Just like the pictures I provided before,versions below Android Q use timestamp naming to insert, or write a renaming logic that is the same as that of higher versions.
The automatic renaming function (for example, video (1).mp4) is implemented in Android 11 and above.
TIL. Are there any docs referencing this?
EDIT: Could you also write it down as comment in the code?
I have not been able to find any official documentation. I found the solution on stackoverflow. ContentResolver.insert always returning null
add the following comment to the code. Is it OK?
When using the ContentResolver.insert() method to insert a file with the same name, an exception will indeed be thrown if the file with the same name already exists. This is because in Android 10 and below, MediaStore does not have the automatic renaming function.
add the following comment to the code. Is it OK?
How about:
Using a duplicate filename that already exists on the device will cause the insertion to fail on Android API 30-.
add the following comment to the code. Is it OK?
How about:
Using a duplicate filename that already exists on the device will cause the insertion to fail on Android API 30-.
i submitted
I've also added some format changes and fixed the nullable saving result.