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

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

    807607
      hi
      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(
                               AudioFormat.Encoding.PCM_SIGNED,
                               baseFormat.getSampleRate(), 16, baseFormat.getChannels(),
                               baseFormat.getChannels() * 2, baseFormat.getSampleRate(),
                               false);
                     din = AudioSystem.getAudioInputStream(decodedFormat, in);
                     DataLine.Info info = new DataLine.Info(SourceDataLine.class, decodedFormat);
                     SourceDataLine line = (SourceDataLine) AudioSystem.getLine(info);
                     if(line != null) {
                          line.open(decodedFormat);
                          byte[] data = new byte[4096];
                          // Start
                          line.start();
                          
                          int nBytesRead;
                          while ((nBytesRead = din.read(data, 0, data.length)) != -1) {     
                               line.write(data, 0, nBytesRead);
                          }
                          // Stop
                          line.drain();
                          line.stop();
                          line.close();
                          din.close();
      thanks in advance

      Message was edited by:
      rsgiridaran@gmail.com