Class PlayerApplet

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Runnable, Accessible

public class PlayerApplet extends Applet implements Runnable
A simple applet that plays an MPEG audio file. The URL (relative to the document base) is passed as the "audioURL" parameter.
Since:
0.0.8
See Also:
  • Field Details

  • Constructor Details

    • PlayerApplet

      public PlayerApplet()
  • Method Details

    • getAudioDevice

      protected AudioDevice getAudioDevice() throws JavaLayerException
      Retrieves the AudioDevice instance that will be used to sound the audio data.
      Returns:
      an audio device instance that will be used to sound the audio stream.
      Throws:
      JavaLayerException
    • getAudioStream

      protected InputStream getAudioStream()
      Retrieves the InputStream that provides the MPEG audio stream data.
      Returns:
      an InputStream from which the MPEG audio data is read, or null if an error occurs.
    • getAudioFileName

      protected String getAudioFileName()
    • getAudioURL

      protected URL getAudioURL()
    • setFileName

      public void setFileName(String name)
      Sets the URL of the audio stream to play.
    • getFileName

      public String getFileName()
    • stopPlayer

      protected void stopPlayer() throws JavaLayerException
      Stops the audio player. If the player is already stopped this method is a no-op.
      Throws:
      JavaLayerException
    • play

      protected void play(InputStream in, AudioDevice dev) throws JavaLayerException
      Decompresses audio data from an InputStream and plays it back through an AudioDevice. The playback is run on a newly created thread.
      Parameters:
      in - The InputStream that provides the MPEG audio data.
      dev - The AudioDevice to use to sound the decompressed data.
      Throws:
      JavaLayerException - if there was a problem decoding or playing the audio data.
    • createPlayerThread

      protected Thread createPlayerThread()
      Creates a new thread used to run the audio player.
      Returns:
      A new Thread that, once started, runs the audio player.
    • init

      public void init()
      Initializes this applet.
      Overrides:
      init in class Applet
    • start

      public void start()
      Starts this applet. An input stream and audio device are created and passed to the play() method.
      Overrides:
      start in class Applet
    • stop

      public void stop()
      Stops this applet. If audio is currently playing, it is stopped.
      Overrides:
      stop in class Applet
    • destroy

      public void destroy()
      Overrides:
      destroy in class Applet
    • run

      public void run()
      The run method for the audio player thread. Simply calls play() on the player to play the entire stream.
      Specified by:
      run in interface Runnable