Skip to content

Commit

Permalink
Fix MP4 videos saving result in 3GP on Android API <=28 (#1188)
Browse files Browse the repository at this point in the history
Co-authored-by: Alex Li <github@alexv525.com>
  • Loading branch information
yishangfei and AlexV525 authored Oct 30, 2024
1 parent 3d1b25c commit ea4c635
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ To know more about breaking changes, see the [Migration Guide][].
### Fixes

- Do not use `privateFileURL` on iOS 18+.
- Fixes saving MP4 videos will result in 3GP on Android API 30-.
- Fixes nullable result returned when saving images and videos on Android.

## 3.5.2

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ class PhotoManagerPlugin(
resultHandler.reply(map)
} catch (e: Exception) {
LogUtils.error("save image error", e)
resultHandler.reply(null)
resultHandler.replyError(call.method, message = null, obj = e)
}
}

Expand All @@ -515,7 +515,7 @@ class PhotoManagerPlugin(
resultHandler.reply(map)
} catch (e: Exception) {
LogUtils.error("save image error", e)
resultHandler.reply(null)
resultHandler.replyError(call.method, message = null, obj = e)
}
}

Expand All @@ -537,7 +537,7 @@ class PhotoManagerPlugin(
resultHandler.reply(map)
} catch (e: Exception) {
LogUtils.error("save video error", e)
resultHandler.reply(null)
resultHandler.replyError(call.method, message = null, obj = e)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,18 @@ interface IDBUtils {
if (relativePath.isNotBlank()) {
put(RELATIVE_PATH, relativePath)
}
} else {
val albumDir = File(
Environment.getExternalStorageDirectory().path,
Environment.DIRECTORY_MOVIES
)
// Check if the directory exist.
File(albumDir, title).path.checkDirs()
// Using a duplicate file name that already exists on the device will cause
// inserts to fail on Android API 29-.
val basename = System.currentTimeMillis().toString()
val newFilePath = File(albumDir, "$basename.${file.extension}").absolutePath
put(DATA, newFilePath)
}
if (latLong != null) {
put(MediaStore.Video.VideoColumns.LATITUDE, latLong.first())
Expand Down

0 comments on commit ea4c635

Please sign in to comment.