我正在构建的录音机将文件保存为THREE_GPP格式。问题在于它用旧文件替换了新文件,因此旧文件丢失了。
mFileName = Environment.getExternalStorageDirectory().getAbsolutePath();
mFileName += "/AudioRecording.3gp";
我尝试了这个但没有结果:
mFileName = Environment.getExternalStorageDirectory().getAbsolutePath();
int entryNumber = 1;
do {
if (this.mFileName == mFileName) {
this.mFileName += "/AudioRecording.3gp" + "(" + entryNumber + ")";
entryNumber++;
}
} while (this.mFileName != mFileName);
音频创建:
mRecorder = new MediaRecorder();
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
mRecorder.setOutputFile(mFileName);
恐怕代码在这里甚至没有针对适当的范围,但是我没有其他方式向编译器表达它必须在该路径中寻找文件。
答案 0 :(得分:1)
您应该更改检查文件是否已存在的方式:
mFileName = Environment.getExternalStorageDirectory().getAbsolutePath();
int entryNumber = 1;
File mFile = new File(mFileName + "/AudioRecording_" + String.valueOf(entryNumber) + ".3gp");
while(mFile.exists()) {
entryNumber++;
mFile = new File(mFileName + "/AudioRecording_" + String.valueOf(entryNumber) + ".3gp");
}
this.mFileName = mFile.getAbsolutePath();
答案 1 :(得分:0)
尝试:
mFileName = Environment.getExternalStorageDirectory().getAbsolutePath()
+ "/AudioRecording"
+ String.valueOf(System.currentTimeMillis())
+ ".3gp";