如果音频持续时间超过1分钟,我试图将记录的音频文件分成较小的块,每个较小的块分别为1分钟,并在Android中将它们视为单独的音频文件。
我通过以下操作录制音频:-
MediaRecorder mAudioRecorder = new MediaRecorder();
mAudioRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mAudioRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mAudioRecorder.setAudioEncoder(MediaRecorder.OutputFormat.AMR_NB);
mAudioRecorder.setOutputFile(outputFile);
startRecording();
当我录制上述音频时,它会被正确录制并播放。现在要剪辑此音频,我正在使用[this] [1]库。
CheapSoundFile cheapSoundFile = CheapSoundFile.create(in_file_path,listner);
int mSampleRate = cheapSoundFile.getSampleRate();
int mSamplesPerFrame = cheapSoundFile.getSamplesPerFrame();
int startFrame = Utilities.secondsToFrames(5.0,mSampleRate, mSamplesPerFrame);
int endFrame = Utilities.secondsToFrames(30.0, mSampleRate,mSamplesPerFrame);
String outputFileDirectory = Environment.getExternalStorageDirectory().getAbsolutePath() + this.getString(R.string.recording_folder);
try
{
File dir = new File(outputFileDirectory);
if (!dir.exists())
{
dir.mkdirs();
}
mFileNumber++;
outputFile = outputFileDirectory + "Clip_" + String.valueOf(mFileNumber) + this.getString(R.string.recording_mp3);
}
catch (Exception e)
{
e.printStackTrace();
}
cheapSoundFile.WriteFile(outputFile , startFrame, endFrame-startFrame);
final CheapSoundFile.ProgressListener listener = new CheapSoundFile.ProgressListener() {
public boolean reportProgress(double frac) {
return true;
}
};
然后,我将剪切后的文件播放为:-
MediaPlayer mediaPlayer = new MediaPlayer();
try
{
if (mediaPlayer != null)
{
mediaPlayer.setDataSource(outputFile);
mediaPlayer.prepare();
}
mediaPlayer.start();
}
catch (Exception e)
{
e.printStackTrace();
}
但是,播放剪辑的音频时出现异常:-
setDataSourceFD failed.: status=0x80000000
对于解决此问题的任何帮助,我们深表感谢。谢谢。