System Sounds in Java

Ky Leggiero picture Ky Leggiero · Oct 13, 2010 · Viewed 20.8k times · Source

I'm trying to code an error dialog, and I want it to call the proper system-specified sound. Is there any way to access system sounds from Java (i.e. Startup sound, default beep, asterisk, critical stop, etc.)?

Note: I know about java.awt.Toolkit.getDefaultToolkit().beep();

Answer

MyPasswordIsLasercats picture MyPasswordIsLasercats · Aug 7, 2013

Here ya go (exclusively for windows:)

final Runnable runnable =
     (Runnable) Toolkit.getDefaultToolkit().getDesktopProperty("win.sound.exclamation");
if (runnable != null) runnable.run();

More sounds for Windows (all pages contain the same content): Java 6, Java 7, Java 8. (Good luck finding some for other OS!)