views:

17

answers:

1

Hello, I am using java Sound with the following code:

public static void main(String[] args) throws Exception
{
    JFrame frame = new JFrame();
    frame.setSize(200,200);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
    JFileChooser fc = new JFileChooser();
    fc.showOpenDialog(null);
    File f = fc.getSelectedFile();
    AudioInputStream ais = AudioSystem.getAudioInputStream(f);
    AudioFormat format = ais.getFormat();
    AudioFormat decodedFormat = new AudioFormat(
                AudioFormat.Encoding.PCM_SIGNED,  // Encoding to use
                    format.getSampleRate(),           // sample rate (same as base format)
                    16,               // sample size in bits (thx to Javazoom)
                    format.getChannels(),             // # of Channels
                    format.getChannels()*2,           // Frame Size
                    format.getSampleRate(),           // Frame Rate
                    false                 // Big Endian
            );
    SourceDataLine line = AudioSystem.getSourceDataLine(decodedFormat);
    AudioInputStream dais = AudioSystem.getAudioInputStream(decodedFormat, ais);
    line.open(decodedFormat);
    line.start();
    byte[] b = new byte[1024];
    int i=0;
    while(true)
    {
        i = dais.read(b, 0, b.length);
        if(i == -1)
            break;
        line.write(b, 0, i);
    }
    line.drain();
    line.stop();
    line.close();
    ais.close();
    dais.close();


}

But to play mp3, tihs requires that I have an SPI on my classpath...its ok, altough I was looking for a way to use the codecs installed in the SO. Is there a way to do that?

A: 

I have used this to play MP3s and it was simple.

Romain Hippeau
I see...but you are not using SO´s codec. You are using a SPI in your classpath like I did.I was trying to make it work with SO´s codec already installed
fredcrs