2 Replies Latest reply: Dec 4, 2006 1:07 AM by 800322 RSS

    Help me ........................... I want to play wave & mp3 files

      i want to play wave and mp3 files using java.
      i can easily play au format files in java using Audio clip interface in applet package.i am tried in javax.sound .sampled package.but if i give .wav or mp3 it throws unsupported file format exception.
      please help me regarding this
      this is my dode
      File file = new File("music.wav");
                     AudioInputStream in = AudioSystem.getAudioInputStream(file);
                     AudioFormat baseFormat = in.getFormat();
                     AudioFormat decodedFormat = new AudioFormat(
                               baseFormat.getSampleRate(), 16, baseFormat.getChannels(),
                               baseFormat.getChannels() * 2, baseFormat.getSampleRate(),
                     din = AudioSystem.getAudioInputStream(decodedFormat, in);
                     DataLine.Info info = new DataLine.Info(SourceDataLine.class, decodedFormat);
                     SourceDataLine line = (SourceDataLine) AudioSystem.getLine(info);
                     if(line != null) {
                          byte[] data = new byte[4096];
                          // Start
                          int nBytesRead;
                          while ((nBytesRead = din.read(data, 0, data.length)) != -1) {     
                               line.write(data, 0, nBytesRead);
                          // Stop
      thanks in advance

      Message was edited by: