多个音频文件不会连接

时间:2013-12-26 17:19:42

标签: java android mediarecorder android-mediarecorder

我正在尝试创建一个简单的录音机,为用户提供“暂停”和“恢复”功能。

由于Android不直接支持此功能,因此只要用户按下“暂停”和“恢复”后缀为_1,_2等,我就会创建单独的文件。

我使用下面的代码将它们连接起来

public void mergeAllAndSave() {
    // TODO Auto-generated method stub
    Enumeration<FileInputStream> allRecordings;
    Vector<FileInputStream> audiofiles = new Vector<FileInputStream>();

    for (int i = 1; i < count+1; i++) {
        try {
            audiofiles.add(new FileInputStream(Environment.getExternalStorageDirectory().getPath() + "/"+ AUDIO_RECORDER_FOLDER + "/" + _filename + "_"+ i + file_exts[currentFormat]));
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    allRecordings = audiofiles.elements();

    SequenceInputStream siStream = new SequenceInputStream(allRecordings);
    try {

        FileOutputStream foStream = new FileOutputStream(Environment.getExternalStorageDirectory().getPath() + "/"+ AUDIO_RECORDER_FOLDER + "/" + _filename + file_exts[currentFormat]);
        int temp;
        while ((temp = siStream.read() ) != -1) {
            foStream.write(temp);   
        }
        foStream.close();
        siStream.close();
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}       

代码工作正常。它给了我一个文件。但是它仅包含第一个文件的内容。无论如何,Logcat都不会显示任何错误。

任何有任何想法的人我在做什么错误?

感谢。

1 个答案:

答案 0 :(得分:0)

对这个问题的回答是here
PS:我不能将此作为评论添加,因为我没有足够的声誉。

相关问题