简体   繁体   English

我的录音机将旧录音替换为新录音,而不是创建新文件

[英]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.

相关问题 Java Swing DrawRect:创建新尺寸替换旧尺寸 - Java Swing DrawRect: creating new replaces old dimensions 更新我的列表视图并添加新的录音机音频 - update my list view whit a new recorder audio 语音转文字应用程序将旧文字替换为新文字 - Speech to text app replaces old text with new ArrayList重用单个对象,而不是创建新的对象 - ArrayList re-using single Object, instead of creating new ones Android:使用全局对象而不是创建新对象 - Android: use a global object instead of creating new ones Java正在读取旧的输入文件,而不是新的文件 - Java is reading old input files, not new ones log4j如何每天自动创建一个新的日志文件而不存档旧文件 - log4j how to auto-create a new log file each day without archiving old ones 强制cxf-codegen-plugin使用现有生成的类,而不是创建新的类 - Force cxf-codegen-plugin to use existing generated classes instead of creating new ones 是否可以在appWidget中重用RemoteViews而不是每次都创建新的? 以及如何存储它们? - Is it possible to reuse RemoteViews in an appWidget instead of creating new ones every time? and how can I store them? 程序正在覆盖我的旧数据,而不是将新数据放在新行中 - Program is over-writing my old data instead of put new data in new row
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM