Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Java sound app works on Mac but not on Windows

807588Feb 6 2009 — edited Feb 6 2009
I am working on a program that needs to play a sound Clip and it doesn't work on XP but it does on OS/X.

I've reduced the problem to this simple test program. On my PC, the sound I hear on the speakers is just a little burst of noise, whereas it's fine on my Mac. I used one of XP's system wav files, and verified that it does play normally on the PC via other means (iTunes, etc.). I'm using the latest JDK/JRE everywhere. Here's the sample code. Anything obviously wrong here?
import java.io.*;
import javax.sound.sampled.*;
 
class ClipTest
{
    public static void main(String args[])
        {
            try
            {
                Clip soundClip;
                AudioInputStream soundStream;
                File audioFile = new File("CHIMES.WAV");
                soundStream = AudioSystem.getAudioInputStream(audioFile);
                AudioFormat format = soundStream.getFormat();
                DataLine.Info info = new DataLine.Info(Clip.class, format);              
                System.out.println(format.toString());
              
                soundClip = (Clip)AudioSystem.getLine(info);
                soundClip.open(soundStream);
                soundClip.start();
            }
            catch (Exception e)
            {
                e.printStackTrace();
            }
        } 
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 6 2009
Added on Feb 6 2009
1 comment
167 views