tags:

views:

399

answers:

4

Hi , I am trying to play a .wav file with java. I need it when a button is pressed to play a short beep sound. I have google it but most of the code wasn't working. Can someone give me a simple code to play a .wav file.

+1  A: 

The snippet here works fine, tested with windows sound:

public static void main(String[] args) {
        AePlayWave aw = new AePlayWave( "C:\\WINDOWS\\Media\\tada.wav" );
        aw.start();     
}
stacker
If you still have issues with that try to change the sound device. See also the tool recommended here http://stackoverflow.com/questions/2175318/how-to-change-default-sound-playback-device-programatically/2216886#2216886
stacker
+1  A: 

Have a look at the open source project jlGui at http://www.javazoom.net/jlgui/jlgui.html which has a BasicPlayer that supports "MP3, OGG Vorbis, FLAC, MONKEY's AUDIO, WAV, AIFF, AU and SPEEX audio formats".

Kennet
A: 

The code here works great for my project. Check it out. http://forums.sun.com/thread.jspa?threadID=5196428

anothem
+1  A: 
Riddick