From 8e226459c966a9f8a560c74ad03b1e3a205374d5 Mon Sep 17 00:00:00 2001 From: Syed Hussain Mehdi Date: Wed, 21 Sep 2022 12:53:12 +0530 Subject: [PATCH] ADD: filename for thumbnail in file --- .../video_thumbnail/VideoThumbnailPlugin.java | 18 ++++++++++++++---- lib/video_thumbnail.dart | 7 +++++-- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/android/src/main/java/xyz/justsoft/video_thumbnail/VideoThumbnailPlugin.java b/android/src/main/java/xyz/justsoft/video_thumbnail/VideoThumbnailPlugin.java index 08ae95a..5818365 100644 --- a/android/src/main/java/xyz/justsoft/video_thumbnail/VideoThumbnailPlugin.java +++ b/android/src/main/java/xyz/justsoft/video_thumbnail/VideoThumbnailPlugin.java @@ -64,6 +64,7 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull final Result result) final int maxw = (int) args.get("maxw"); final int timeMs = (int) args.get("timeMs"); final int quality = (int) args.get("quality"); + final String fileName = (String) args.get("filename"); final String method = call.method; executor.execute(new Runnable() { @@ -76,7 +77,7 @@ public void run() { try { if (method.equals("file")) { final String path = (String) args.get("path"); - thumbnail = buildThumbnailFile(video, headers, path, format, maxh, maxw, timeMs, quality); + thumbnail = buildThumbnailFile(video, headers, path, format, maxh, maxw, timeMs, quality, fileName); handled = true; } else if (method.equals("data")) { @@ -134,20 +135,26 @@ private byte[] buildThumbnailData(final String vidPath, final HashMap headers, String path, int format, int maxh, int maxw, int timeMs, - int quality) { + int quality, String fileName) { // Log.d(TAG, String.format("buildThumbnailFile( format:%d, maxh:%d, maxw:%d, // timeMs:%d, quality:%d )", format, maxh, maxw, timeMs, quality)); final byte bytes[] = buildThumbnailData(vidPath, headers, format, maxh, maxw, timeMs, quality); final String ext = formatExt(format); final int i = vidPath.lastIndexOf("."); - String fullpath = vidPath.substring(0, i + 1) + ext; + String fullpath = null; + if (fileName != null) { + fullpath = fileName + "." + ext; + } + else { + fullpath = vidPath.substring(0, i + 1) + ext; + } final boolean isLocalFile = (vidPath.startsWith("/") || vidPath.startsWith("file://")); if (path == null && !isLocalFile) { path = context.getCacheDir().getAbsolutePath(); } - if (path != null) { + if (path != null && fileName == null) { if (path.endsWith(ext)) { fullpath = path; } else { @@ -161,6 +168,9 @@ private String buildThumbnailFile(final String vidPath, final HashMap{ @@ -43,7 +45,8 @@ class VideoThumbnail { 'maxh': maxHeight, 'maxw': maxWidth, 'timeMs': timeMs, - 'quality': quality + 'quality': quality, + 'filename' : fileName }; return await _channel.invokeMethod('file', reqMap); }