-
Notifications
You must be signed in to change notification settings - Fork 832
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
How to show progress bar with percentage. #100
Comments
I would like to know how this can be done as well. Any leads? |
+1 |
1 similar comment
+1 |
Hey guys, I just formatted the string and extracted the time of video compressed and I came up with this method which returns the percentProgress in float data type. It's a hack but I hope it helps :
|
Or you can use my function
|
Thanks @kimcy929. I adapted your method with milliseconds to make the progress more smooth if you work with short videos (like in my case, less or equal to 3sec.). Otherwise, you only see 33%, 66%, 99%. long videoLengthInMillis;
private void getVideoLength(String basePath) {
MediaPlayer mp = MediaPlayer.create(ctx, Uri.parse(basePath));
videoLengthInMillis = TimeUnit.MILLISECONDS.toMillis(mp.getDuration());
mp.release();
Log.d(TAG, "onStart: VideoLeng -> " + videoLengthInMillis);
}
Pattern pattern = Pattern.compile("time=([\\d\\w:]{8}[\\w.][\\d]+)");
private long getProgress(String message) {
if (message.contains("speed")) {
Matcher matcher = pattern.matcher(message);
matcher.find();
String tempTime = String.valueOf(matcher.group(1));
Log.d(TAG, "getProgress: tempTime " + tempTime);
String[] arrayTime = tempTime.split("[:|.]");
long currentTime =
TimeUnit.HOURS.toMillis(Long.parseLong(arrayTime[0]))
+ TimeUnit.MINUTES.toMillis(Long.parseLong(arrayTime[1]))
+ TimeUnit.SECONDS.toMillis(Long.parseLong(arrayTime[2]))
+ Long.parseLong(arrayTime[3]);
long percent = 100 * currentTime/videoLengthInMillis;
Log.d(TAG, "currentTime -> " + currentTime + "s % -> " + percent);
return percent;
}
return 0;
} |
Creating MediaPlayer Instance is heavy and consumes a lot of memory We can use MetadataRetriever for this
|
You can also retrieve the duration from the message
|
@Cdik I tried your answer, but the problem is that FFmpeg updates the progress every 0.5 second. So, even when using milliseconds, the progress is still Do you have any solution for this? |
Hi @HBiSoft , it has been a long time I haven't used this library but I don't recall having 33-66-99 when using millis. I had something more smooth, like 11-22-33-.... There's maybe something wrong in your implementation. Can you show your code where you deal with the progress? |
@Cdik Thank you for replying. Yes mine isn't that bad, I was maybe over exaggerating. But when saving short videos it does "jump" quite a bit. I was hoping to get a smooth progression of percentages (more accurate), but seems like this isn't possible, especially with shorter videos. |
Please let me know how to show the progress in percentage(10%, 20% completed like this). We can calculate the percentage from this line in FFmpegExecuteAsyncTask .
But Here I can not get the percentage in this line
(publishProgress(line))
. Please let me know how to show the progress with percentage. Please help me to solve this. Thanks in advance.The text was updated successfully, but these errors were encountered: