我有一个应用程序,可以MediaRecorder from MIC
在有电话时使用记录音频,我需要能够在通话结束时保存此录音的最后 x 分钟 - 例如拆分创建的录音的音频文件。
我搜索了这个,我能找到的只是如何.wav
通过直接从文件中删除字节来拆分文件。但是我将文件保存在:
MediaRecorder.OutputFormat.THREE_GPP
使用编码:
MediaRecorder.OutputFormat.AMR_NB
并且我没有找到拆分此类文件的方法。
这是我的代码:
public class Recorder
{
private MediaRecorder myRecorder;
public String outputFile = null;
private Context context = null;
public Recorder(Context context_app)
{
context = context_app;
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss", Locale.getDefault());
df.setTimeZone(TimeZone.getDefault());
String time = df.format(new Date());
outputFile = Environment.getExternalStorageDirectory().
getAbsolutePath() + "/"+time+".3gpp"; //this is the folder in which your Audio file willl save
myRecorder = new MediaRecorder();
myRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
myRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
myRecorder.setAudioEncoder(MediaRecorder.OutputFormat.AMR_NB);
myRecorder.setOutputFile(outputFile);
}
public void start() {
try {
myRecorder.prepare();
myRecorder.start();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
Toast.makeText(context, e.getMessage(),
Toast.LENGTH_SHORT).show();
// prepare() fails
e.printStackTrace();
}
Toast.makeText(context, "Start recording...",
Toast.LENGTH_SHORT).show();
}
public void stop() {
try {
myRecorder.stop();
myRecorder.reset();
myRecorder.release();
myRecorder = null;
Toast.makeText(context, "Stop recording...",
Toast.LENGTH_SHORT).show();
} catch (RuntimeException e) {
// no valid audio/video data has been received
e.printStackTrace();
}
}
}
如何THREE_GPP
按时间拆分并将我需要的部分保存在单独的文件中?
另外,我对直接操作字节和文件一无所知,所以请详细说明它是否是您解决它的方式。
提前致谢