Click here to Skip to main content
11,707,470 members (80,707 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Java
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 )

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 3-Oct-12 19:01pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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/[^]
  Permalink  
v2

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

  Print Answers RSS
0 Maciej Los 195
1 Mika Wendelius 190
2 OriginalGriff 156
3 Sergey Alexandrovich Kryukov 145
4 chainerlt 110
0 OriginalGriff 9,178
1 Sergey Alexandrovich Kryukov 8,562
2 CPallini 5,189
3 Maciej Los 4,806
4 Mika Wendelius 3,706


Advertise | Privacy | Mobile
Web03 | 2.8.150819.1 | Last Updated 4 Oct 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100