Click here to Skip to main content
15,891,943 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
how to read .wma song file in java. I'm using this code. but this code is error.

(Error == javax.sound.sampled.UnsupportedAudioFileException: could not get audio input stream from input file )

Java
private void playAudio() {
        try {
            File soundFile =
                    new File("Track_1.wma");
            audioInputStream = AudioSystem.getAudioInputStream(soundFile);
            audioFormat = audioInputStream.getFormat();
            System.out.println(audioFormat);

            DataLine.Info dataLineInfo =
                    new DataLine.Info(
                    SourceDataLine.class,
                    audioFormat);
            sourceDataLine =
                    (SourceDataLine) AudioSystem.getLine(
                    dataLineInfo);
            new PlayThread().start();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

class PlayThread extends Thread {
        byte tempBuffer[] = new byte[10000];
        public void run() {
            try {
                sourceDataLine.open(audioFormat);
                sourceDataLine.start();
                int cnt;
                while ((cnt = audioInputStream.read(
                        tempBuffer, 0, tempBuffer.length)) != -1
                        && stopPlayback == false) {
                    if (cnt > 0) {
                        sourceDataLine.write(
                                tempBuffer, 0, cnt);
                    }
                }
                sourceDataLine.drain();
                sourceDataLine.close();
            } catch (Exception e) {
                e.printStackTrace();
            }



Please help me.
Thanks.
Posted

1 solution

That exception will stay. *.wma files are not supported by standard.

The sound support is currently bad in Java. The Sound API is not developed actively, there is no developer left after oracle toke over the Java development.

Simplest solution would be to use *.wav files.

Check this for some information on the Sound API:
Java Sound Programmer Guide[^] @ oracle.com

There is a lib available for mp3 support under JMF:
Java MP3 PlugIn[^]

And the FOBS project is said to be supporting WMA-Files. But that Project is also not continuing:
http://fobs.sourceforge.net/[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900