How do I play an alert sound in Java FX 2?
Is there a way of using the OS default notification sound?
How do I play an alert sound in Java FX 2? Is there a
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Play a sound with pure JavaFX
Simply use an instance of
AudioClip. This one is very suitable for just playing single short sounds.Play a default notification sound
Concerning Windows OS there is a way accessing properties via
java.awt.Toolkit. A returned sound property is a simpleRunnablewhich can be fired directly without any worries about sound sources etc.Use the example below to see how both options work (you have to add ‘alert.wav’ to your src folder).