|
|
|
@ -8,6 +8,7 @@ import android.os.Bundle; |
|
|
|
|
import android.view.View; |
|
|
|
|
import android.widget.LinearLayout; |
|
|
|
|
import android.widget.ProgressBar; |
|
|
|
|
|
|
|
|
|
import java.io.File; |
|
|
|
|
|
|
|
|
|
import com.frank.ffmpeg.AudioPlayer; |
|
|
|
@ -35,6 +36,8 @@ public class AudioHandleActivity extends BaseActivity { |
|
|
|
|
private int viewId; |
|
|
|
|
private FFmpegHandler ffmpegHandler; |
|
|
|
|
|
|
|
|
|
private final static boolean useFFmpeg = true; |
|
|
|
|
|
|
|
|
|
@SuppressLint("HandlerLeak") |
|
|
|
|
private Handler mHandler = new Handler() { |
|
|
|
|
@Override |
|
|
|
@ -97,6 +100,7 @@ public class AudioHandleActivity extends BaseActivity { |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 调用ffmpeg处理音频 |
|
|
|
|
* |
|
|
|
|
* @param srcFile srcFile |
|
|
|
|
*/ |
|
|
|
|
private void doHandleAudio(final String srcFile) { |
|
|
|
@ -110,13 +114,15 @@ public class AudioHandleActivity extends BaseActivity { |
|
|
|
|
} |
|
|
|
|
switch (viewId) { |
|
|
|
|
case R.id.btn_transform://转码
|
|
|
|
|
// String transformFile = PATH + File.separator + "transform.aac";
|
|
|
|
|
// commandLine = FFmpegUtil.transformAudio(srcFile, transformFile);
|
|
|
|
|
//使用mp3lame进行转码
|
|
|
|
|
String inputFile = PATH + File.separator + "hello.aac"; |
|
|
|
|
String transformFile = PATH + File.separator + "transform.mp3"; |
|
|
|
|
String transformFile; |
|
|
|
|
if (useFFmpeg) { //使用FFmpeg转码
|
|
|
|
|
transformFile = PATH + File.separator + "transformAudio.mp3"; |
|
|
|
|
commandLine = FFmpegUtil.transformAudio(srcFile, transformFile); |
|
|
|
|
} else { //使用MediaCodec与mp3lame转mp3
|
|
|
|
|
transformFile = PATH + File.separator + "transformAudio.mp3"; |
|
|
|
|
Mp3Converter mp3Converter = new Mp3Converter(); |
|
|
|
|
mp3Converter.convertToMp3(inputFile, transformFile); |
|
|
|
|
mp3Converter.convertToMp3(srcFile, transformFile); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
case R.id.btn_cut://剪切(注意原文件与剪切文件格式一致,文件绝对路径最好不包含中文、特殊字符)
|
|
|
|
|
String suffix = FileUtil.getFileSuffix(srcFile); |
|
|
|
@ -137,7 +143,11 @@ public class AudioHandleActivity extends BaseActivity { |
|
|
|
|
if (!FileUtil.checkFileExist(appendFile)) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
String mixFile = PATH + File.separator + "mix.aac"; |
|
|
|
|
String mixSuffix = FileUtil.getFileSuffix(srcFile); |
|
|
|
|
if (mixSuffix == null || mixSuffix.isEmpty()) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
String mixFile = PATH + File.separator + "mix" + mixSuffix; |
|
|
|
|
commandLine = FFmpegUtil.mixAudio(srcFile, appendFile, mixFile); |
|
|
|
|
break; |
|
|
|
|
case R.id.btn_play_audio://解码播放(AudioTrack)
|
|
|
|
|