Skip to content

Commit

Permalink
fix: video thumbnail generation crash
Browse files Browse the repository at this point in the history
  • Loading branch information
Dwynr committed Apr 19, 2023
1 parent b2d769c commit fe469ff
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 8 deletions.
4 changes: 2 additions & 2 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ android {
applicationId "io.filen.app"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 2057
versionName "2.0.57"
versionCode 2058
versionName "2.0.58"
}

splits {
Expand Down
8 changes: 4 additions & 4 deletions ios/Filen.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Filen/Filen.entitlements;
CURRENT_PROJECT_VERSION = 2057;
CURRENT_PROJECT_VERSION = 2058;
DEVELOPMENT_TEAM = 7YTW5D2K7P;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Filen/Info.plist;
Expand All @@ -657,7 +657,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 2.0.57;
MARKETING_VERSION = 2.0.58;
OTHER_LDFLAGS = (
"$(inherited)",
"-ObjC",
Expand Down Expand Up @@ -685,15 +685,15 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Filen/Filen.entitlements;
CURRENT_PROJECT_VERSION = 2057;
CURRENT_PROJECT_VERSION = 2058;
DEVELOPMENT_TEAM = 7YTW5D2K7P;
INFOPLIST_FILE = Filen/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 2.0.57;
MARKETING_VERSION = 2.0.58;
OTHER_LDFLAGS = (
"$(inherited)",
"-ObjC",
Expand Down
2 changes: 1 addition & 1 deletion ios/Filen.xcodeproj/xcshareddata/xcschemes/Filen.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
buildConfiguration = "Release"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "filen-mobile",
"version": "2.0.57",
"version": "2.0.58",
"private": true,
"scripts": {
"android": "react-native run-android",
Expand Down
87 changes: 87 additions & 0 deletions patches/expo-video-thumbnails+7.2.1.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
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..71400ab 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
@@ -40,22 +40,27 @@ class VideoThumbnailsModule : Module() {
val thumbnail = GetThumbnail(sourceFilename, options, context).execute()
?: throw GenerateThumbnailException()

- try {
- val path = FileUtilities.generateOutputPath(context.cacheDir, "VideoThumbnails", "jpg")
- FileOutputStream(path).use { outputStream ->
- thumbnail.compress(Bitmap.CompressFormat.JPEG, (options.quality * 100).toInt(), outputStream)
- }
- promise.resolve(
- VideoThumbnailResult(
- uri = Uri.fromFile(File(path)).toString(),
- width = thumbnail.width,
- height = thumbnail.height
+ if(thumbnail == null){
+ promise.reject(ERROR_TAG, "Thumbnail generation failed", GenerateThumbnailException())
+ }
+ else{
+ try {
+ val path = FileUtilities.generateOutputPath(context.cacheDir, "VideoThumbnails", "jpg")
+ FileOutputStream(path).use { outputStream ->
+ thumbnail.compress(Bitmap.CompressFormat.JPEG, (options.quality * 100).toInt(), outputStream)
+ }
+ promise.resolve(
+ VideoThumbnailResult(
+ uri = Uri.fromFile(File(path)).toString(),
+ width = thumbnail.width,
+ height = thumbnail.height
+ )
)
- )
- } catch (ex: IOException) {
- promise.reject(ERROR_TAG, ex.message, ex)
- } catch (ex: RuntimeException) {
- promise.reject(ERROR_TAG, ex.message, ex)
+ } catch (ex: IOException) {
+ promise.reject(ERROR_TAG, ex.message, ex)
+ } catch (ex: RuntimeException) {
+ promise.reject(ERROR_TAG, ex.message, ex)
+ }
}
}
}
@@ -71,21 +76,28 @@ class VideoThumbnailsModule : Module() {

private class GetThumbnail(private val sourceFilename: String, private val videoOptions: VideoThumbnailOptions, private val context: Context) {
fun execute(): Bitmap? {
- val retriever = MediaMetadataRetriever()
+ try{
+ 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)
+ 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)
+ }
+ } else {
+ retriever.setDataSource(sourceFilename, videoOptions.headers)
}
- } else {
- retriever.setDataSource(sourceFilename, videoOptions.headers)
+
+ return retriever.getFrameAtTime(videoOptions.time.toLong() * 1000, MediaMetadataRetriever.OPTION_CLOSEST_SYNC)
}
+ catch(e: RuntimeException){
+ Log.e(ERROR_TAG, "setDataSource failed")

- return retriever.getFrameAtTime(videoOptions.time.toLong() * 1000, MediaMetadataRetriever.OPTION_CLOSEST_SYNC)
+ return null
+ }
}
}

0 comments on commit fe469ff

Please sign in to comment.