0

I saw a few pages about it, but I found the solution to the problem, would like to join two mp3 tracks into one, but at the time he writes the output (juntos4.mp3, it is just the songs, someone can help me?

"My" Code...

                FileInputStream fis1 = new FileInputStream("/sdcard/1408586436107.mp3");  // first source file
                FileInputStream fis2 = new FileInputStream("/sdcard/1408586281745.mp3");//second source file
                SequenceInputStream sis = new SequenceInputStream(fis1, fis2);
                FileOutputStream fos = new FileOutputStream("/sdcard/juntos4.mp3");//destinationfile

                int temp;

                try {
                    while ((temp = sis.read())!= -1){

                        fos.write(temp);

                    }

                    fis1.close();
                    fis2.close();
                    sis.close();
                    fos.close();

                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }


        }
Jared Burrows
  • 54,294
  • 25
  • 151
  • 185

1 Answers1

1

create the FILE not the directory!

newFile.createNewFile();


FileInputStream fistream1 = new FileInputStream(newFile1 );  // first source file
    FileInputStream fistream2= new FileInputStream(newFile2 );//second source file
    Vector<FileInputStream> v = new Vector<FileInputStream>();
    v.add(fistream1);
    v.add(fistream2);
    SequenceInputStream sistream = new SequenceInputStream(fistream1, fistream2);

    if(!newFile.exists()){
        newFile.createNewFile();
        FileOutputStream fostream=new FileOutputStream(newFile, true);
        int temp;

        while( ( temp = sistream.read() ) != -1)
        {
            System.out.print( (char) temp ); // to print at DOS prompt
            fostream.write((byte)temp);   // to write to file
        }

        fostream.close();
        sistream.close();
        fistream1.close();
        fistream2.close();
    }
Akshay Mukadam
  • 2,388
  • 1
  • 27
  • 40
  • and third, it seems the sequenceinputstream works not properly for me, when i use the two-arguemnt-constructor, instead use the constructor with the enumerator. http://stackoverflow.com/questions/19489316/unable-to-merge-two-mp3-files/20683490#20683490 yes man, you are very right!! – Martin Frank Aug 21 '14 at 06:05
  • 1
    hei i just realised it's copy/paste from my answer at that time, hahaa ^^ – Martin Frank Aug 21 '14 at 06:06
  • good luck with that! i'm glad i produced working code there ^^ – Martin Frank Aug 21 '14 at 06:06
  • @MartinFrank I have used ur code before I was Unable to find my code where I stored. So I just provided r code. Sorry for that. I give u an upvote for that – Akshay Mukadam Aug 21 '14 at 06:08
  • it' ok, its very ok, it's not my code per se... i'm glad i could help somebody then and now ^^ – Martin Frank Aug 21 '14 at 06:09
  • sorry do not have answered above, had problems with my connection (it always happens in brazil), i will tests the 12:00pm, this time i'm in the work, thanks for all return... – Diogo Odelli Aug 21 '14 at 11:50
  • in my early tests, it did not work, he did not create the new file .. question in the vector "V" is used ?, newFile1 newFile2 and can be "/sdcard/1408586281745.mp3". newfile, defines where the track is created, right? – Diogo Odelli Aug 21 '14 at 16:30
  • os arquivos mp3 se juntam, porém ele emite apenas o som de um deles :/ – Diogo Odelli Aug 21 '14 at 17:03
  • mp3 files are added, but it only emits the sound of one of them: / – Diogo Odelli Aug 21 '14 at 17:04