MediaHandleActivity接入基类Activity

MediaHandleActivity接入基类Activity
pull/107/head
xufulong 5 years ago
parent 8157a2d6e0
commit 2e7d905393
  1. 8
      app/src/main/java/com/frank/ffmpeg/activity/AudioHandleActivity.java
  2. 106
      app/src/main/java/com/frank/ffmpeg/activity/MediaHandleActivity.java
  3. 8
      app/src/main/java/com/frank/ffmpeg/activity/VideoHandleActivity.java
  4. 46
      app/src/main/res/layout/activity_media_handle.xml

@ -30,7 +30,7 @@ public class AudioHandleActivity extends BaseActivity {
private String appendFile = PATH + File.separator + "test.mp3";
private final static int MSG_BEGIN = 311;
private final static int MSG_FINISH = 312;
private ProgressBar progress_audio;
private ProgressBar progressAudio;
private LinearLayout layoutAudioHandle;
private int viewId;
@ -41,11 +41,11 @@ public class AudioHandleActivity extends BaseActivity {
super.handleMessage(msg);
switch (msg.what) {
case MSG_BEGIN:
progress_audio.setVisibility(View.VISIBLE);
progressAudio.setVisibility(View.VISIBLE);
layoutAudioHandle.setVisibility(View.GONE);
break;
case MSG_FINISH:
progress_audio.setVisibility(View.GONE);
progressAudio.setVisibility(View.GONE);
layoutAudioHandle.setVisibility(View.VISIBLE);
break;
default:
@ -68,7 +68,7 @@ public class AudioHandleActivity extends BaseActivity {
}
private void initView() {
progress_audio = getView(R.id.progress_audio);
progressAudio = getView(R.id.progress_audio);
layoutAudioHandle = getView(R.id.layout_audio_handle);
initViewsWithClick(
R.id.btn_transform,

@ -7,9 +7,9 @@ import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import com.frank.ffmpeg.FFmpegCmd;
import com.frank.ffmpeg.R;
@ -22,18 +22,19 @@ import java.io.File;
* 使用ffmpeg进行音视频合成与分离
* Created by frank on 2018/1/23.
*/
public class MediaHandleActivity extends AppCompatActivity implements View.OnClickListener{
public class MediaHandleActivity extends BaseActivity {
private final static String TAG = MediaHandleActivity.class.getSimpleName();
private static final String PATH = Environment.getExternalStorageDirectory().getPath();
private String srcFile = PATH + File.separator + "hello.mp4";
private String videoFile = PATH + File.separator + "flash-tree.mp4";//flash-tree.mp4
String temp = PATH + File.separator + "temp.mp4";
private String videoFile;
private String temp = PATH + File.separator + "temp.mp4";
private boolean isMux;
private final static int MSG_MUX = 100;
private final static int MSG_BEGIN = 101;
private final static int MSG_FINISH = 102;
private ProgressBar progress_media;
private ProgressBar progressMedia;
private int viewId;
private LinearLayout layoutMediaHandle;
@SuppressLint("HandlerLeak")
private Handler mHandler = new Handler(){
@ -73,12 +74,12 @@ public class MediaHandleActivity extends AppCompatActivity implements View.OnCli
}
break;
case MSG_BEGIN:
progress_media.setVisibility(View.VISIBLE);
setGone();
progressMedia.setVisibility(View.VISIBLE);
layoutMediaHandle.setVisibility(View.GONE);
break;
case MSG_FINISH:
progress_media.setVisibility(View.GONE);
setVisible();
progressMedia.setVisibility(View.GONE);
layoutMediaHandle.setVisibility(View.VISIBLE);
break;
default:
break;
@ -86,83 +87,70 @@ public class MediaHandleActivity extends AppCompatActivity implements View.OnCli
}
};
@Override
int getLayoutId() {
return R.layout.activity_media_handle;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_media_handle);
hideActionBar();
initView();
}
private void initView() {
progress_media = (ProgressBar) findViewById(R.id.progress_media) ;
findViewById(R.id.btn_mux).setOnClickListener(this);
findViewById(R.id.btn_extract_audio).setOnClickListener(this);
findViewById(R.id.btn_extract_video).setOnClickListener(this);
}
private void setVisible() {
findViewById(R.id.btn_mux).setVisibility(View.VISIBLE);
findViewById(R.id.btn_extract_audio).setVisibility(View.VISIBLE);
findViewById(R.id.btn_extract_video).setVisibility(View.VISIBLE);
progressMedia = getView(R.id.progress_media);
layoutMediaHandle = getView(R.id.layout_media_handle);
initViewsWithClick(
R.id.btn_mux,
R.id.btn_extract_audio,
R.id.btn_extract_video
);
}
private void setGone() {
findViewById(R.id.btn_mux).setVisibility(View.GONE);
findViewById(R.id.btn_extract_audio).setVisibility(View.GONE);
findViewById(R.id.btn_extract_video).setVisibility(View.GONE);
@Override
public void onViewClick(View view) {
viewId = view.getId();
selectFile();
}
@Override
public void onClick(View v) {
int handleType;
switch (v.getId()){
case R.id.btn_mux:
handleType = 0;
break;
case R.id.btn_extract_audio:
handleType = 1;
break;
case R.id.btn_extract_video:
handleType = 2;
break;
default:
handleType = 0;
break;
}
doHandleMedia(handleType);
void onSelectedFile(String filePath) {
doHandleMedia(filePath);
}
/**
* 调用ffmpeg处理音视频
* @param handleType handleType
* @param srcFile srcFile
*/
private void doHandleMedia(int handleType){
private void doHandleMedia(String srcFile) {
String[] commandLine = null;
switch (handleType){
case 0://音视频合成
if (!FileUtil.checkFileExist(videoFile)){
return;
}
if (!FileUtil.checkFileExist(srcFile)){
return;
}
if (!FileUtil.isVideo(srcFile)) {
showToast(getString(R.string.wrong_video_format));
return;
}
switch (viewId){
case R.id.btn_mux://音视频合成
try {
//视频文件有音频,先把纯视频文件抽取出来
commandLine = FFmpegUtil.extractVideo(videoFile, temp);
videoFile = srcFile;
commandLine = FFmpegUtil.extractVideo(srcFile, temp);
isMux = true;
} catch (Exception e) {
e.printStackTrace();
}
break;
case 1://提取音频
if (!FileUtil.checkFileExist(srcFile)){
return;
}
case R.id.btn_extract_audio://提取音频
String extractAudio = PATH + File.separator + "extractAudio.aac";
commandLine = FFmpegUtil.extractAudio(srcFile, extractAudio);
break;
case 2://提取视频
if (!FileUtil.checkFileExist(srcFile)){
return;
}
case R.id.btn_extract_video://提取视频
String extractVideo = PATH + File.separator + "extractVideo.mp4";
commandLine = FFmpegUtil.extractVideo(srcFile, extractVideo);
break;
@ -176,7 +164,7 @@ public class MediaHandleActivity extends AppCompatActivity implements View.OnCli
* 执行ffmpeg命令行
* @param commandLine commandLine
*/
private void executeFFmpegCmd(final String[] commandLine){
private void executeFFmpegCmd(final String[] commandLine) {
if(commandLine == null){
return;
}

@ -25,7 +25,7 @@ public class VideoHandleActivity extends BaseActivity {
private static final String PATH = Environment.getExternalStorageDirectory().getPath();
private ProgressBar progress_video;
private ProgressBar progressVideo;
private LinearLayout layoutVideoHandle;
private int viewId;
@ -36,11 +36,11 @@ public class VideoHandleActivity extends BaseActivity {
super.handleMessage(msg);
switch (msg.what){
case MSG_BEGIN:
progress_video.setVisibility(View.VISIBLE);
progressVideo.setVisibility(View.VISIBLE);
layoutVideoHandle.setVisibility(View.GONE);
break;
case MSG_FINISH:
progress_video.setVisibility(View.GONE);
progressVideo.setVisibility(View.GONE);
layoutVideoHandle.setVisibility(View.VISIBLE);
break;
default:
@ -63,7 +63,7 @@ public class VideoHandleActivity extends BaseActivity {
}
private void intView() {
progress_video = getView(R.id.progress_video);
progressVideo = getView(R.id.progress_video);
layoutVideoHandle = getView(R.id.layout_video_handle);
initViewsWithClick(
R.id.btn_video_transform,

@ -5,31 +5,33 @@
android:layout_height="match_parent"
tools:context="com.frank.ffmpeg.activity.MediaHandleActivity">
<Button
android:id="@+id/btn_mux"
android:layout_width="wrap_content"
<LinearLayout
android:id="@+id/layout_media_handle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="120dp"
android:text="@string/media_mux"/>
android:orientation="vertical"
android:gravity="center_horizontal">
<Button
android:id="@+id/btn_mux"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="120dp"
android:text="@string/media_mux"/>
<Button
android:id="@+id/btn_extract_audio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/media_extra_audio"
android:layout_marginTop="10dp"
android:layout_centerHorizontal="true"
android:layout_below="@+id/btn_mux"/>
<Button
android:id="@+id/btn_extract_audio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/media_extra_audio"
android:layout_marginTop="10dp" />
<Button
android:id="@+id/btn_extract_video"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/media_extract_video"
android:layout_marginTop="10dp"
android:layout_centerHorizontal="true"
android:layout_below="@+id/btn_extract_audio"/>
<Button
android:id="@+id/btn_extract_video"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/media_extract_video"
android:layout_marginTop="10dp" />
</LinearLayout>
<ProgressBar
android:id="@+id/progress_media"

Loading…
Cancel
Save