javasystem-sounds

System Sounds in Java


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();


Solution

  • 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!)