Package jmri.jmrit

Class Sound


  • public class Sound
    extends java.lang.Object
    Provide simple way to load and play sounds in JMRI.

    This is placed in the jmri.jmrit package by process of elimination. It doesn't belong in the base jmri package, as it's not a basic interface. Nor is it a specific implementation of a basic interface, which would put it in jmri.jmrix. It seems most like a "tool using JMRI", or perhaps a tool for use with JMRI, so it was placed in jmri.jmrit.

    See Also:
    jmri.jmrit.sound
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static long LARGE_SIZE  
    • Constructor Summary

      Constructors 
      Constructor Description
      Sound​(java.io.File file)
      Create a Sound object using the media file
      Sound​(java.lang.String path)
      Create a Sound object using the media file at path
      Sound​(java.net.URL url)
      Create a Sound object using the media URL
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Closes the sound.
      protected void finalize()
      boolean getAutoClose()
      Get if the clip is closed automatically.
      void loop()
      Play the sound as an endless loop
      void loop​(int count)
      Play the sound in a loop count times.
      void play()
      Play the sound once.
      static void playSoundBuffer​(byte[] wavData)
      Play a sound from a buffer
      void setAutoClose​(boolean autoClose)
      Set if the clip be closed automatically.
      void stop()
      Stop playing a loop.
      • Methods inherited from class java.lang.Object

        clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Sound

        public Sound​(@Nonnull
                     java.lang.String path)
              throws java.lang.NullPointerException
        Create a Sound object using the media file at path
        Parameters:
        path - path, portable or absolute, to the media
        Throws:
        java.lang.NullPointerException - if path cannot be converted into a URL by FileUtilSupport.findURL(java.lang.String)
      • Sound

        public Sound​(@Nonnull
                     java.io.File file)
              throws java.net.MalformedURLException
        Create a Sound object using the media file
        Parameters:
        file - reference to the media
        Throws:
        java.net.MalformedURLException - if file cannot be converted into a valid URL
      • Sound

        public Sound​(@Nonnull
                     java.net.URL url)
              throws java.lang.NullPointerException
        Create a Sound object using the media URL
        Parameters:
        url - path to the media
        Throws:
        java.lang.NullPointerException - if URL is null
    • Method Detail

      • setAutoClose

        public void setAutoClose​(boolean autoClose)
        Set if the clip be closed automatically.
        Parameters:
        autoClose - true if closed automatically
      • getAutoClose

        public boolean getAutoClose()
        Get if the clip is closed automatically.
        Returns:
        true if closed automatically
      • close

        public void close()
        Closes the sound.
      • finalize

        protected void finalize()
                         throws java.lang.Throwable
        Overrides:
        finalize in class java.lang.Object
        Throws:
        java.lang.Throwable
      • play

        public void play()
        Play the sound once.
      • loop

        public void loop()
        Play the sound as an endless loop
      • loop

        public void loop​(int count)
        Play the sound in a loop count times. Use Clip.LOOP_CONTINUOUSLY to create an endless loop.
        Parameters:
        count - the number of times to loop
      • stop

        public void stop()
        Stop playing a loop.
      • playSoundBuffer

        public static void playSoundBuffer​(byte[] wavData)
        Play a sound from a buffer
        Parameters:
        wavData - data to play