show the progress of audio transformation

show the progress of audio transformation
pull/166/head
xufulong 5 years ago
parent a1b818e644
commit 414935382c
  1. 24
      app/src/main/java/com/frank/ffmpeg/activity/AudioHandleActivity.java
  2. 7
      app/src/main/res/layout/activity_audio_handle.xml
  3. 25
      app/src/main/res/layout/item_progress.xml

@ -7,11 +7,12 @@ import android.os.Message;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import com.frank.ffmpeg.AudioPlayer;
import com.frank.ffmpeg.R;
@ -22,6 +23,7 @@ import com.frank.ffmpeg.util.FileUtil;
import static com.frank.ffmpeg.handler.FFmpegHandler.MSG_BEGIN;
import static com.frank.ffmpeg.handler.FFmpegHandler.MSG_FINISH;
import static com.frank.ffmpeg.handler.FFmpegHandler.MSG_PROGRESS;
/**
* Using ffmpeg command to handle audio
@ -33,8 +35,9 @@ public class AudioHandleActivity extends BaseActivity {
private final static String PATH = Environment.getExternalStorageDirectory().getPath();
private String appendFile = PATH + File.separator + "heart.m4a";
private ProgressBar progressAudio;
private LinearLayout layoutAudioHandle;
private LinearLayout layoutProgress;
private TextView txtProgress;
private int viewId;
private FFmpegHandler ffmpegHandler;
@ -47,13 +50,23 @@ public class AudioHandleActivity extends BaseActivity {
super.handleMessage(msg);
switch (msg.what) {
case MSG_BEGIN:
progressAudio.setVisibility(View.VISIBLE);
layoutProgress.setVisibility(View.VISIBLE);
layoutAudioHandle.setVisibility(View.GONE);
break;
case MSG_FINISH:
progressAudio.setVisibility(View.GONE);
layoutProgress.setVisibility(View.GONE);
layoutAudioHandle.setVisibility(View.VISIBLE);
break;
case MSG_PROGRESS:
int progress = msg.arg1;
int duration = msg.arg2;
if (progress > 0) {
txtProgress.setVisibility(View.VISIBLE);
txtProgress.setText(String.format(Locale.getDefault(), "%d%%", progress));
} else {
txtProgress.setVisibility(View.INVISIBLE);
}
break;
default:
break;
}
@ -75,7 +88,8 @@ public class AudioHandleActivity extends BaseActivity {
}
private void initView() {
progressAudio = getView(R.id.progress_audio);
layoutProgress = getView(R.id.layout_progress);
txtProgress = getView(R.id.txt_progress);
layoutAudioHandle = getView(R.id.layout_audio_handle);
initViewsWithClick(
R.id.btn_transform,

@ -68,11 +68,10 @@
android:layout_marginTop="10dp" />
</LinearLayout>
<ProgressBar
android:id="@+id/progress_audio"
<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>

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="gone">
<ProgressBar
android:id="@+id/progress_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/txt_progress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:textColor="@color/colorAccent"
android:text="100%"
android:textSize="18sp"
android:gravity="center_horizontal"
android:visibility="invisible"/>
</LinearLayout>
Loading…
Cancel
Save