show progress of media transformation

show progress of media transformation
pull/166/head
xufulong 4 years ago
parent 3f4c942273
commit 6973f31260
  1. 25
      app/src/main/java/com/frank/ffmpeg/activity/MediaHandleActivity.java
  2. 7
      app/src/main/res/layout/activity_media_handle.xml

@ -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,

@ -33,11 +33,10 @@
android:layout_marginTop="10dp" />
</LinearLayout>
<ProgressBar
android:id="@+id/progress_media"
<include
layout="@layout/item_progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:visibility="gone"/>
android:layout_centerInParent="true"/>
</RelativeLayout>

Loading…
Cancel
Save