4 Replies Latest reply: Oct 26, 2012 10:10 AM by gimbal2 RSS

    Alert Sound

    ellias2007
      Hi every body
      i am Java Programmer but NEW in the JavaFX domain...

      Simply, i need to fire an "alert sound" somewhere in my application...
      Please help me with the SIMPLEST code ...

      suppose that i have the file "abc.mp3" in the right directory, than what i have to do in order to import it and run it...


      Many thanks for any simple useful help
        • 1. Re: Alert Sound
          csh
          See here:

          http://docs.oracle.com/javafx/2/api/javafx/scene/media/AudioClip.html
          • 2. Re: Alert Sound
            ellias2007
            Let me first thank you for your quick, simple and useful answer....

            Just, how to refer to my file in the right directory (My file : Pop.aiff, in the same directory with my Java class),

            i tried :

            AudioClip plonkSound = new AudioClip("Pop.aiff");
            AudioClip plonkSound = new AudioClip("/Pop.aiff");

            i get errors..
            while when i did :

            Image Back = new Image(getClass().getResourceAsStream("Back.jpg"));

            i can easily refer to Back.jpg without any error...
            Thanks
            • 3. Re: Alert Sound
              ellias2007
              Thanks it is Okey ... i put :

              AudioClip plonkSound = new AudioClip(getClass().getResource("Pop.aiff").toString());

              and it works...

              Thanks again
              • 4. Re: Alert Sound
                gimbal2
                Beware: you will probably want to get in the habit of using
                getClass().getClassLoader().getResourceAsStream("path/to/bla.ext");
                especially when you learn about packages and you start to use them (which you should btw). Using getClass().getResource() works for you right now, but I suggest you attempt to find the javadoc (using Google) that describes this method, as an exercise to help you learn how to find your own information.