Java playing sounds. Is there a default system sound?
Hi I am trying to write an application that will 开发者_StackOverflow中文版play morse code. I just wanted to know if there was a default system sound in java like some beep, or do I have to download some sound file from the internet?
You can:
Print the ASCII bell character to the console (will emit a beep sound):
public class DoBeep {
public static main(String args[]) {
System.out.print("\007"); // bell ASCII char
System.out.flush();
}
}
Use the beep()
method that will use the buzzer on the motherboard:
import java.awt.*;
public class DoBeep {
public static void main(String args[]) {
Toolkit.getDefaultToolkit().beep();
}
}
Have a look at the Java Sound API, which can play MIDI tones.
You may want to look at jMorse for some tips. This isn't to discourage you from your effort, but rather to provide a reference.
精彩评论