0

I'm trying to create a simple recorder which gives 'pause' and 'resume' functionality to the user.

Since Android does not support this directly, I'm creating individual files whenever the user presses 'Pause' and 'Resume' with the suffixes _1, _2, so on.

I use the code below to concatenate them

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();
    }
}       

The code works fine. It gives me a single file. However it contains the contents of the first file only. Logcat does not show any errors, whatsoever.

Anyone with any ideas what is the mistake I am making?

Thanks.

Vivek Todi
  • 361
  • 1
  • 9
  • 24

1 Answers1

0

Answer to this question is here.
PS: I cannot add this as a comment because I do not have sufficient reputation.

Community
  • 1
  • 1
Bhoot
  • 2,614
  • 1
  • 19
  • 36