• Post Reply Bookmark Topic Watch Topic
  • New Topic

What's the best way to play a very short sound

 
Ren Shao
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm writing a swing application, it loads data into a JTable. I want to play a beep (a very short wav file) every time a new entry is inserted into the table. (a bit like the alert sound in windows)

I know there're different ways to play sound. I don't want to use a full-feature sound library because you tend to write more code and it going to use more RAM. I just need a simply way to play the sound.

Any suggestions?
 
Don Solomon
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
import java.awt.*

Toolkit tk=Toolkit.getDefaultToolkit();
tk.beep();
 
Ren Shao
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, but what about playing my specified wav file, not the default beep sound?
 
Kai Witte
Ranch Hand
Posts: 356
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I am not sure if it still is the way to go, but the old way is to use Applet#newAudioClip. It sounds very wrong when you don't even use an applet, but it isn't. Prior to 1.2 the method getAudioClip had to be used, which is not static, so that an instance of Applet had to be created just for this.

But maybe there is something new in 1.5 or 1.6?

Kai
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java 1.4 introduced the javax.sound package. See here for an example of how to play sound files. AIFF, AU and WAV files are supported out of the box.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!