Class ModernAudioClip

  • All Implemented Interfaces:
    AudioClip

    public class ModernAudioClip
    extends java.lang.Object
    implements AudioClip
    The implementation of this class uses Java 1.3 features, but nothing beyond that. In particular, AudioSystem.getClip() is NOT used, that being a Java 1.5 feature.

    Instances of this class are completely thread safe, meaning that the five methods play(), loop(), stop(), pause(), and resume() can all be called by different threads, and can all be intertwined. All such calls [including construction] are safely placed onto an event dispatch queue and are handled sequentially by one thread.

    • Constructor Summary

      Constructors 
      Constructor Description
      ModernAudioClip​(java.io.InputStream sndFile)
      Construction actually takes place in a different thread; this constructs only a dummy container.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void loop()
      Plays the audio clip once through, then jumps back to beginning, playing it through again and again, indefinitely.
      void pause()
      Puts the audio clip into paused state, if not already.
      void play()
      Plays the audio clip once through.
      void resume()
      Resumes the clip after paused state, if clip was paused previously.
      void stop()
      Stops a playing or looping audio clip.
      • Methods inherited from class java.lang.Object

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

      • ModernAudioClip

        public ModernAudioClip​(java.io.InputStream sndFile)
        Construction actually takes place in a different thread; this constructs only a dummy container. In case of errors during construction, the clip is disabled, and any further operations on this clip are ignored. Construction errors are printed to System.err, but are not reported.

        The sndFile should have markSupported() return true.

        Parameters:
        sndFile - An InputStream consisting of the contents of a WAV file (or AU file). Some other formats may work also, but I'm not sure which ones do. MP3 files certainly DON'T work.
    • Method Detail

      • play

        public void play()
        Description copied from interface: AudioClip
        Plays the audio clip once through. This always causes the playing to start from beginning of clip, even in cases where clip is already playing or looping.
        Specified by:
        play in interface AudioClip
      • loop

        public void loop()
        Description copied from interface: AudioClip
        Plays the audio clip once through, then jumps back to beginning, playing it through again and again, indefinitely. This always causes the playing to start from beginning of clip, even in cases where clip is already playing or looping.
        Specified by:
        loop in interface AudioClip
      • stop

        public void stop()
        Description copied from interface: AudioClip
        Stops a playing or looping audio clip. The next time the clip is played or looped it will start from beginning of clip.
        Specified by:
        stop in interface AudioClip
      • pause

        public void pause()
        Description copied from interface: AudioClip
        Puts the audio clip into paused state, if not already. When the clip is resumed it will continue exactly where it left off when it was paused. If play(), loop(), or stop() are called while the clip is paused, then upon resume() the clip will behave as if calling those operations in the same order immediately upon resume.
        Specified by:
        pause in interface AudioClip
      • resume

        public void resume()
        Description copied from interface: AudioClip
        Resumes the clip after paused state, if clip was paused previously. For clarification on required behavior of pause/resume please see discussion on pause().
        Specified by:
        resume in interface AudioClip
        See Also:
        AudioClip.pause()