[英]My audio recorder replaces old recordings with new ones instead of creating a new file
The audio recorder i am building saves files in THREE_GPP format. 我正在构建的录音机将文件保存为THREE_GPP格式。 The problem is that it replaces the new file with the old one so old files are lost. 问题在于它将新文件替换为旧文件,从而丢失了旧文件。
mFileName = Environment.getExternalStorageDirectory().getAbsolutePath();
mFileName += "/AudioRecording.3gp";
I have tried this with no results: 我尝试了这个,但没有结果:
mFileName = Environment.getExternalStorageDirectory().getAbsolutePath();
int entryNumber = 1;
do {
if (this.mFileName == mFileName) {
this.mFileName += "/AudioRecording.3gp" + "(" + entryNumber + ")";
entryNumber++;
}
} while (this.mFileName != mFileName);
Audio creation: 音频创作:
mRecorder = new MediaRecorder();
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
mRecorder.setOutputFile(mFileName);
I'm afraid that the code doesn't even target the proper scope here, but i have no other way of expressing to the compiler that it has to look for a file in that path. 恐怕代码在这里甚至都没有针对适当的范围,但是我没有其他方式向编译器表达它必须在该路径中寻找文件。
You should change how you are checking if the file already exists: 您应该更改检查文件是否已存在的方式:
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();
Try like: 试试:
mFileName = Environment.getExternalStorageDirectory().getAbsolutePath()
+ "/AudioRecording"
+ String.valueOf(System.currentTimeMillis())
+ ".3gp";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.