-
Notifications
You must be signed in to change notification settings - Fork 319
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix MP4 videos saving result in 3GP on Android API <=28 #1188
Conversation
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. |
It is still unclear why the PR fixes the issue. Could you provide a minimal reproducible example? |
example code
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 test1.mp4 |
@@ -428,11 +429,6 @@ interface IDBUtils { | |||
} | |||
refreshStream() | |||
|
|||
val shouldKeepPath = if (!isAboveAndroidQ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you also keep the condition? The fix should work without removing it, correct?
folderName: String?, | ||
): String { | ||
var albumFolderPath: String = Environment.getExternalStorageDirectory().path | ||
if (android.os.Build.VERSION.SDK_INT < 29) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What standard do we following here? Should we use MOVIE
as much as possible?
return albumFolderPath | ||
} | ||
|
||
private fun createDirIfNotExist(dirPath: String): String? { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We seem to already have a helper method checkDir
I added it in line 455 according to your latest code. |
// check if the directories exist | ||
"$albumDir${File.separator}$title".checkDirs() | ||
val timestamp = System.currentTimeMillis().toString() | ||
// Create a video file. If you use file.name, assetEntity may be empty. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why we cannot use the filename?
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. |
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."
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. |
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. add the following comment to the code. Is it OK?
|
How about:
|
Using a duplicate file name that already exists on the device will cause inserts to fail on less than Android API 30.
i submitted |
I've also added some format changes and fixed the nullable saving result. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution.
Fixed the issue that the video format changes to 3gp when saving mp4 videos to the album on Android 9