From 6973f312607cab74b8f76067639ba8ff70a8ebed Mon Sep 17 00:00:00 2001 From: xufulong <839789740@qq.com> Date: Thu, 18 Jun 2020 00:19:51 +0800 Subject: [PATCH] show progress of media transformation show progress of media transformation --- .../ffmpeg/activity/MediaHandleActivity.java | 25 ++++++++++++++----- .../main/res/layout/activity_media_handle.xml | 7 +++--- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/com/frank/ffmpeg/activity/MediaHandleActivity.java b/app/src/main/java/com/frank/ffmpeg/activity/MediaHandleActivity.java index bce7130..8b02747 100644 --- a/app/src/main/java/com/frank/ffmpeg/activity/MediaHandleActivity.java +++ b/app/src/main/java/com/frank/ffmpeg/activity/MediaHandleActivity.java @@ -10,7 +10,7 @@ import android.os.Message; import android.util.Log; import android.view.View; import android.widget.LinearLayout; -import android.widget.ProgressBar; +import android.widget.TextView; import com.frank.ffmpeg.R; import com.frank.ffmpeg.handler.FFmpegHandler; @@ -18,10 +18,12 @@ import com.frank.ffmpeg.util.FFmpegUtil; import com.frank.ffmpeg.util.FileUtil; import java.io.File; +import java.util.Locale; import static com.frank.ffmpeg.handler.FFmpegHandler.MSG_BEGIN; import static com.frank.ffmpeg.handler.FFmpegHandler.MSG_CONTINUE; import static com.frank.ffmpeg.handler.FFmpegHandler.MSG_FINISH; +import static com.frank.ffmpeg.handler.FFmpegHandler.MSG_PROGRESS; /** * using ffmpeg to handle media @@ -34,7 +36,8 @@ public class MediaHandleActivity extends BaseActivity { private String videoFile; private String temp = PATH + File.separator + "temp.mp4"; - private ProgressBar progressMedia; + private LinearLayout layoutProgress; + private TextView txtProgress; private int viewId; private LinearLayout layoutMediaHandle; private FFmpegHandler ffmpegHandler; @@ -46,7 +49,7 @@ public class MediaHandleActivity extends BaseActivity { super.handleMessage(msg); switch (msg.what) { case MSG_CONTINUE: - String audioFile = PATH + File.separator + "tiger.mp3";//tiger.mp3 + String audioFile = PATH + File.separator + "tiger.mp3"; String muxFile = PATH + File.separator + "media-mux.mp4"; try { @@ -75,13 +78,22 @@ public class MediaHandleActivity extends BaseActivity { } break; case MSG_BEGIN: - progressMedia.setVisibility(View.VISIBLE); + layoutProgress.setVisibility(View.VISIBLE); layoutMediaHandle.setVisibility(View.GONE); break; case MSG_FINISH: - progressMedia.setVisibility(View.GONE); + layoutProgress.setVisibility(View.GONE); layoutMediaHandle.setVisibility(View.VISIBLE); break; + case MSG_PROGRESS: + int progress = msg.arg1; + if (progress > 0) { + txtProgress.setVisibility(View.VISIBLE); + txtProgress.setText(String.format(Locale.getDefault(), "%d%%", progress)); + } else { + txtProgress.setVisibility(View.INVISIBLE); + } + break; default: break; } @@ -103,7 +115,8 @@ public class MediaHandleActivity extends BaseActivity { } private void initView() { - progressMedia = getView(R.id.progress_media); + layoutProgress = getView(R.id.layout_progress); + txtProgress = getView(R.id.txt_progress); layoutMediaHandle = getView(R.id.layout_media_handle); initViewsWithClick( R.id.btn_mux, diff --git a/app/src/main/res/layout/activity_media_handle.xml b/app/src/main/res/layout/activity_media_handle.xml index c610a03..7c1e351 100644 --- a/app/src/main/res/layout/activity_media_handle.xml +++ b/app/src/main/res/layout/activity_media_handle.xml @@ -33,11 +33,10 @@ android:layout_marginTop="10dp" /> - + android:layout_centerInParent="true"/>