-1

I want merge multiple mp3 file in android but for example I just do this with two file :

 FileInputStream fileInputStream = new FileInputStream(soundFile.getAbsolutePath() + 0);
                FileInputStream fileInputStream1 = new FileInputStream(soundFile.getAbsolutePath() + 1);
                SequenceInputStream sequenceInputStream = new SequenceInputStream(fileInputStream, fileInputStream1);

                FileOutputStream fileOutputStream = new FileOutputStream(soundFile.getAbsolutePath());

                int temp;
                while ((temp = sequenceInputStream.read()) != -1) {
                    fileOutputStream.write(temp);
                }

                fileInputStream.close();
                fileInputStream1.close();
                sequenceInputStream.close();
                fileOutputStream.close();

I recorded two sound with "ttt.mp30" and "ttt.mp31" file. then I want to merge it to "ttt.mp3"

but when I use this code for merge, it just create the ttt.mp3 witch play ttt.mp30 but it doesn't play ttt.mp31 file

whats the problem ?

thanks

EDIT :

if I use :

SequenceInputStream sequenceInputStream = new SequenceInputStream(fileInputStream1, fileInputStream);

insted of :

SequenceInputStream sequenceInputStream = new SequenceInputStream(fileInputStream, fileInputStream1);

the ttt.mp3 just play ttt.mp31 file

Edit :

the record option :

mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
        mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
        mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
Abbb
  • 1
  • 2

1 Answers1

0
 import java.io.*;
 public class TwoFiles
 {
public static void main(String args[]) throws IOException
{
    FileInputStream fistream1 = new FileInputStream("path\\1.mp3");  // first source file
    FileInputStream fistream2 = new FileInputStream("path\\2.mp3");//second source file
    SequenceInputStream sistream = new SequenceInputStream(fistream1, fistream2);
    FileOutputStream fostream = new FileOutputStream("path\\final.mp3");//destinationfile

    int temp;

    while( ( temp = sistream.read() ) != -1)
    {
        // System.out.print( (char) temp ); // to print at DOS prompt
        fostream.write(temp);   // to write to file
    }
    fostream.close();
    sistream.close();
    fistream1.close();
    fistream2.close();
}
}
sasikumar
  • 12,540
  • 3
  • 28
  • 48