0

//I am trying to concatenate a list of mp3 files using java. But when I am running the code I am getting the following error:

        //javax.sound.sampled.UnsupportedAudioFileException: could not get audio input stream from input file
            at javax.sound.sampled.AudioSystem.getAudioInputStream(AudioSystem.java:1170)
            at soundConcat.main(soundConcat.java:42)

//this is the code

         String[]   strFilename = {"a","b","c","d","e","f"};
                        for (int i = 0; i < 6; i++)
                {
                        File    soundFile = new File("./sounds/"+strFilename[i]+".mp3");
                        AudioInputStream    audioInputStream = null;
                        try
                    {
                //getting an error on the next line
            audioInputStream = AudioSystem.getAudioInputStream(soundFile);
                    }
                    catch (Exception e)
                    {               
                        e.printStackTrace();        
                    }
       //some more operations here
    }
    }
Nick Div
  • 5,338
  • 12
  • 65
  • 127

1 Answers1

0

I don't know how this works but just copied jl.jar & mp3spi.jar and tritonus_share.jar to my classpath and its just working. Sorry for no explaination, even I don't know how this worked but if someone could explain it, I would appreciate it. But this time there is a new problem, the generated output file is in wav format and I am not able to play even using the regular players in the OS.

Nick Div
  • 5,338
  • 12
  • 65
  • 127
  • 2
    *"even I don't know how this worked"* Java Sound works on Service Provider interfaces for information on how to read/write specific encodings. All that is necessary is to add the SPI to the run-time class-path in order to add the ability to read (and sometimes write) that encoding. The relevant Jar in this case is almost certainly `mp3spi.jar`. – Andrew Thompson Nov 15 '12 at 08:11