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