Skip to content

Commit

Permalink
fix: bitmap dimension can be 0 on Android
Browse files Browse the repository at this point in the history
  • Loading branch information
maitrungduc1410 committed Nov 10, 2024
1 parent 7fd3ff3 commit caa150a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class VideoTrimmerUtil {
// public static final int THUMB_WIDTH = (SCREEN_WIDTH_FULL - RECYCLER_VIEW_PADDING * 2) / VIDEO_MAX_TIME;
public static int mThumbWidth = 0; // make it automatic
public static final int THUMB_HEIGHT = UnitConverter.dpToPx(50); // x2 for better resolution
public static final int THUMB_WIDTH = UnitConverter.dpToPx(25); // x2 for better resolution
private static final int THUMB_RESOLUTION_RES = 2; // double thumb resolution for better quality

public static FFmpegSession trim(String inputFile, String outputFile, int videoDuration, long startMs, long endMs, final VideoTrimListener callback) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,9 @@ private void mediaPrepared() {
Bitmap bitmap = mediaMetadataRetriever.getFrameAtTime(0, MediaMetadataRetriever.OPTION_CLOSEST_SYNC);

if (bitmap != null) {
VideoTrimmerUtil.mThumbWidth = VideoTrimmerUtil.THUMB_HEIGHT * bitmap.getWidth() / bitmap.getHeight();
int bitmapHeight = bitmap.getHeight() > 0 ? bitmap.getHeight() : VideoTrimmerUtil.THUMB_HEIGHT;
int bitmapWidth = bitmap.getWidth() > 0 ? bitmap.getWidth() : VideoTrimmerUtil.THUMB_WIDTH;
VideoTrimmerUtil.mThumbWidth = VideoTrimmerUtil.THUMB_HEIGHT * bitmapWidth / bitmapHeight;
}

VideoTrimmerUtil.SCREEN_WIDTH_FULL = this.getScreenWidthInPortraitMode();
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": "react-native-video-trim",
"version": "2.2.10",
"version": "2.2.11",
"description": "Video trimmer for your React Native app",
"main": "lib/commonjs/index",
"module": "lib/module/index",
Expand Down

0 comments on commit caa150a

Please sign in to comment.