-
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f39a3a1
Update IDBUtils.kt
yishangfei 9ae3fe1
Update IDBUtils.kt
yishangfei 80d6438
Merge branch 'fluttercandies:main' into main
yishangfei 668dd27
Update IDBUtils.kt
yishangfei 610361e
🎨 Format code
AlexV525 ff897f3
🥅 Throws exceptions when failed to save
AlexV525 ec0429e
Merge branch 'refs/heads/main' into yichangfei-main
AlexV525 137e5ed
📝 CHANGELOG
AlexV525 b11a1ef
💡 Correct comment
AlexV525 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,7 @@ import java.io.File | |
import java.io.FileInputStream | ||
import java.io.InputStream | ||
import java.net.URLConnection | ||
import android.text.TextUtils | ||
|
||
@Suppress("Deprecation", "InlinedApi", "Range") | ||
interface IDBUtils { | ||
|
@@ -428,11 +429,6 @@ interface IDBUtils { | |
} | ||
refreshStream() | ||
|
||
val shouldKeepPath = if (!isAboveAndroidQ) { | ||
val dir = Environment.getExternalStorageDirectory() | ||
file.absolutePath.startsWith(dir.path) | ||
} else false | ||
|
||
val timestamp = System.currentTimeMillis() / 1000 | ||
val values = ContentValues().apply { | ||
put( | ||
|
@@ -454,22 +450,23 @@ interface IDBUtils { | |
if (relativePath.isNotBlank()) { | ||
put(RELATIVE_PATH, relativePath) | ||
} | ||
} else { | ||
val albumDir = File(getAlbumFolderPath(title)) | ||
val videoFilePath = File(albumDir, file.name).absolutePath | ||
put(DATA, videoFilePath) | ||
} | ||
if (latLong != null) { | ||
put(MediaStore.Video.VideoColumns.LATITUDE, latLong.first()) | ||
put(MediaStore.Video.VideoColumns.LONGITUDE, latLong.last()) | ||
} | ||
if (shouldKeepPath) { | ||
put(DATA, filePath) | ||
} | ||
} | ||
|
||
return insertUri( | ||
context, | ||
inputStream, | ||
MediaStore.Video.Media.EXTERNAL_CONTENT_URI, | ||
values, | ||
shouldKeepPath | ||
false | ||
)?.copy(orientation = orientation ?: rotationDegrees) | ||
} | ||
|
||
|
@@ -493,6 +490,37 @@ interface IDBUtils { | |
return getAssetEntity(context, id.toString()) | ||
} | ||
|
||
private fun getAlbumFolderPath( | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. What standard do we following here? Should we use |
||
albumFolderPath += File.separator + Environment.DIRECTORY_DCIM; | ||
} | ||
albumFolderPath = if (TextUtils.isEmpty(folderName)) { | ||
var baseFolderName = Environment.DIRECTORY_MOVIES | ||
createDirIfNotExist( | ||
Environment.getExternalStoragePublicDirectory(baseFolderName).path | ||
) ?: albumFolderPath | ||
} else { | ||
createDirIfNotExist(albumFolderPath + File.separator + folderName) ?: albumFolderPath | ||
} | ||
return albumFolderPath | ||
} | ||
|
||
private fun createDirIfNotExist(dirPath: String): String? { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We seem to already have a helper method |
||
val dir = File(dirPath) | ||
return if (!dir.exists()) { | ||
if (dir.mkdirs()) { | ||
dir.path | ||
} else { | ||
null | ||
} | ||
} else { | ||
dir.path | ||
} | ||
} | ||
|
||
fun assetExists(context: Context, id: String): Boolean { | ||
val columns = arrayOf(_ID) | ||
context.contentResolver.logQuery(allUri, columns, "$_ID = ?", arrayOf(id), null).use { | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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?