Class ClipPlayer

  • All Implemented Interfaces:
    java.lang.Cloneable, java.util.EventListener, javax.sound.sampled.LineListener, Actor, Executable, FiringsRecordable, Initializable, TypedActor, Changeable, Debuggable, DebugListener, Derivable, Instantiable, ModelErrorHandler, MoMLExportable, Moveable, Nameable

    public class ClipPlayer
    extends TypedAtomicActor
    implements javax.sound.sampled.LineListener
    An actor that plays an audio clip given in a file. Each time this actor fires, it starts playing the clip given by the fileOrURL parameter. If the overlay parameter is false (the default), then it will terminate any previously playing clip before playing the new instance. Otherwise, it will mix in the new instance with the currently playing clip. If playToCompletion is true, then each firing returns only after the clip has finished playing. Otherwise, the firing returns immediately, and another firing will result in either truncating the current clip or overlaying a new instance of it, depending on the value of overlay. If outputOnlyOnStop is false (the default), then this actor will produce an output (with value false) only when the current clip has finished playing. Otherwise, it will also produce an output (with value true) when the clip starts playing. If playToCompletion is true, both of these outputs will occur in the same firing. Otherwise, when the clip starts or stops (which occurs in another thread), this actor will request that the director fire it, and when it fires, it will produce the appropriate output.
    Since:
    Ptolemy II 6.1
    Version:
    $Id$
    Author:
    Edward A. Lee
    See Also:
    LiveSound, AudioCapture, AudioReader, AudioWriter
    Pt.AcceptedRating:
    Red (eal)
    Pt.ProposedRating:
    Yellow (eal)
    • Field Detail

      • fileOrURL

        public FilePortParameter fileOrURL
        The file or URL giving the audio clip. This is set by default to a file containing a voice signal.
      • output

        public TypedIOPort output
        Output port used to indicate starts and stops. This is a boolean port. A true output indicates that a clip has been started, and a false output indicates that one has stopped.
      • outputOnlyOnStop

        public Parameter outputOnlyOnStop
        If true, only produce a single FALSE token upon stop. Useful for chaining clips together in the SDF domain where multiple output tokens will cause an exception to be thrown.
      • overlay

        public Parameter overlay
        If true, then if the actor fires before the previous clip has finished playing, then a new instance of the clip will be played on top of the tail of the previous instance, as long as the underlying mixer supports adding additional clips. This is a boolean that is false by default, which means that the clip is stopped and restarted each time the actor fires.
      • playToCompletion

        public Parameter playToCompletion
        If true, then play the clip to completion before returning from firing. This is a boolean that defaults to false.
      • stop

        public TypedIOPort stop
        Stop playback when this port receives a token of any type, if any clip is playing.
      • trigger

        public TypedIOPort trigger
        The trigger. When this port receives a token of any type, the actor begins playing the audio clip.
      • _clips

        protected java.util.List<javax.sound.sampled.Clip> _clips
        The clip to playback.
    • Method Detail

      • attributeChanged

        public void attributeChanged​(Attribute attribute)
                              throws IllegalActionException
        React to a change in an attribute. In this case, check the value of the path attribute to make sure it is a valid URI.
        Overrides:
        attributeChanged in class NamedObj
        Parameters:
        attribute - The attribute that changed.
        Throws:
        IllegalActionException - If the change is not acceptable to this container (not thrown in this base class).
      • fire

        public void fire()
                  throws IllegalActionException
        Produce any pending outputs indicating that the clip has started or stopped, then if the stop input has a token, stop all clips that may be playing, then if the trigger input has a token, start a new instance of the clip playing. If playToCompletion is true, then do not return until the clip has completed playing. Otherwise, return immediately.
        Specified by:
        fire in interface Executable
        Overrides:
        fire in class AtomicActor<TypedIOPort>
        Throws:
        IllegalActionException - Not thrown in this class.
      • update

        public void update​(javax.sound.sampled.LineEvent event)
        Called by the clip to notify this object of changes in the status of a clip.
        Specified by:
        update in interface javax.sound.sampled.LineListener
        Parameters:
        event - The event, with one of type OPEN, CLOSE, START, STOP of class LineEvent.Type.