Skip to content
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: error setDataSource failed: status = 0x80000000 when using expo-video-thumbnails #5953

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions app/containers/message/Components/Attachments/Video.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,11 @@ type TThumbnailImage = string | null;
type ThumbnailProps = {
url: string;
status: TDownloadState;
isSupportedVideoType: boolean;
encrypted?: boolean;
};

const Thumbnail = ({ url, status, encrypted = false }: ThumbnailProps) => {
const Thumbnail = ({ url, status, isSupportedVideoType, encrypted = false }: ThumbnailProps) => {
const { theme } = useTheme();

let icon: TIconsName = status === 'downloaded' ? 'play-filled' : 'arrow-down-circle';
Expand All @@ -67,8 +68,7 @@ const Thumbnail = ({ url, status, encrypted = false }: ThumbnailProps) => {

const generateThumbnail = async () => {
try {
if (!url) return;

if (!url || encrypted || !isSupportedVideoType) return;
const { uri } = await getThumbnailAsync(url, {
time: 1
});
Expand Down Expand Up @@ -151,7 +151,12 @@ const Video = ({
<>
<Markdown msg={msg} username={user.username} getCustomEmoji={getCustomEmoji} style={[isReply && style]} theme={theme} />
<Touchable onPress={_onPress} style={messageStyles.image} background={Touchable.Ripple(colors.surfaceNeutral)}>
<Thumbnail status={status} url={url} encrypted={isEncrypted} />
<Thumbnail
status={status}
url={url}
encrypted={isEncrypted}
isSupportedVideoType={!!currentFile.video_type && isTypeSupported(currentFile.video_type)}
/>
</Touchable>
</>
);
Expand Down
83 changes: 83 additions & 0 deletions patches/expo-video-thumbnails+7.9.0.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
diff --git a/node_modules/expo-video-thumbnails/android/src/main/java/expo/modules/videothumbnails/Exceptions.kt b/node_modules/expo-video-thumbnails/android/src/main/java/expo/modules/videothumbnails/Exceptions.kt
index eadd828..b93114e 100644
--- a/node_modules/expo-video-thumbnails/android/src/main/java/expo/modules/videothumbnails/Exceptions.kt
+++ b/node_modules/expo-video-thumbnails/android/src/main/java/expo/modules/videothumbnails/Exceptions.kt
@@ -10,3 +10,6 @@ class GenerateThumbnailException :

class FilePermissionsModuleNotFound :
CodedException("File permissions module not found")
+
+class InvalidSourceFilenameException :
+ CodedException("Invalid source URI")
\ No newline at end of file
diff --git a/node_modules/expo-video-thumbnails/android/src/main/java/expo/modules/videothumbnails/VideoThumbnailsModule.kt b/node_modules/expo-video-thumbnails/android/src/main/java/expo/modules/videothumbnails/VideoThumbnailsModule.kt
index 4da98be..12a08a4 100644
--- a/node_modules/expo-video-thumbnails/android/src/main/java/expo/modules/videothumbnails/VideoThumbnailsModule.kt
+++ b/node_modules/expo-video-thumbnails/android/src/main/java/expo/modules/videothumbnails/VideoThumbnailsModule.kt
@@ -32,15 +32,17 @@ class VideoThumbnailsModule : Module() {
Name("ExpoVideoThumbnails")

AsyncFunction("getThumbnail") { sourceFilename: String, options: VideoThumbnailOptions, promise: Promise ->
- if (URLUtil.isFileUrl(sourceFilename) && !isAllowedToRead(Uri.decode(sourceFilename).replace("file://", ""))) {
- throw ThumbnailFileException()
- }
-
withModuleScope(promise) {
- val thumbnail = GetThumbnail(sourceFilename, options, context).execute()
- ?: throw GenerateThumbnailException()
-
try {
+ if (!URLUtil.isValidUrl(sourceFilename)) throw InvalidSourceFilenameException()
+
+ if (URLUtil.isFileUrl(sourceFilename) && !isAllowedToRead(Uri.decode(sourceFilename).replace("file://", ""))) {
+ throw ThumbnailFileException()
+ }
+
+ val thumbnail = GetThumbnail(sourceFilename, options, context).execute()
+ ?: throw GenerateThumbnailException()
+
val path = FileUtilities.generateOutputPath(context.cacheDir, "VideoThumbnails", "jpg")
FileOutputStream(path).use { outputStream ->
thumbnail.compress(Bitmap.CompressFormat.JPEG, (options.quality * 100).toInt(), outputStream)
@@ -73,19 +75,30 @@ class VideoThumbnailsModule : Module() {
fun execute(): Bitmap? {
val retriever = MediaMetadataRetriever()

- if (URLUtil.isFileUrl(sourceFilename)) {
- retriever.setDataSource(Uri.decode(sourceFilename).replace("file://", ""))
- } else if (URLUtil.isContentUrl(sourceFilename)) {
- val fileUri = Uri.parse(sourceFilename)
- val fileDescriptor = context.contentResolver.openFileDescriptor(fileUri, "r")!!.fileDescriptor
- FileInputStream(fileDescriptor).use { inputStream ->
- retriever.setDataSource(inputStream.fd)
+ try {
+ if (URLUtil.isFileUrl(sourceFilename)) {
+ retriever.setDataSource(Uri.decode(sourceFilename).replace("file://", ""))
+ } else if (URLUtil.isContentUrl(sourceFilename)) {
+ val fileUri = Uri.parse(sourceFilename)
+ context.contentResolver.openFileDescriptor(fileUri, "r")?.use { parcelFileDescriptor ->
+ FileInputStream(parcelFileDescriptor.fileDescriptor).use { inputStream ->
+ retriever.setDataSource(inputStream.fd)
+ }
+ }
+ } else {
+ retriever.setDataSource(sourceFilename, videoOptions.headers)
}
- } else {
- retriever.setDataSource(sourceFilename, videoOptions.headers)
- }

- return retriever.getFrameAtTime(videoOptions.time.toLong() * 1000, MediaMetadataRetriever.OPTION_CLOSEST_SYNC)
+ return retriever.getFrameAtTime(
+ videoOptions.time.toLong() * 1000,
+ MediaMetadataRetriever.OPTION_CLOSEST_SYNC
+ )
+ } catch (e: Exception) {
+ Log.e(ERROR_TAG, "Unable to retrieve source file")
+ return null
+ } finally {
+ retriever.release()
+ }
}
}