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

ADD: filename for thumbnail in file #127

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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")) {
Expand Down Expand Up @@ -134,20 +135,26 @@ private byte[] buildThumbnailData(final String vidPath, final HashMap<String, St

private String buildThumbnailFile(final String vidPath, final HashMap<String, String> 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 {
Expand All @@ -161,6 +168,9 @@ private String buildThumbnailFile(final String vidPath, final HashMap<String, St
}
}
}
else {
fullpath = path + fullpath;
}

try {
FileOutputStream f = new FileOutputStream(fullpath);
Expand Down
7 changes: 5 additions & 2 deletions lib/video_thumbnail.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ class VideoThumbnail {
int maxHeight = 0,
int maxWidth = 0,
int timeMs = 0,
int quality = 10}) async {
int quality = 10,
String? fileName,
}) async {
assert(video.isNotEmpty);
if (video.isEmpty) return null;
final reqMap = <String, dynamic>{
Expand All @@ -43,7 +45,8 @@ class VideoThumbnail {
'maxh': maxHeight,
'maxw': maxWidth,
'timeMs': timeMs,
'quality': quality
'quality': quality,
'filename' : fileName
};
return await _channel.invokeMethod('file', reqMap);
}
Expand Down