mediaframe.mpeg1.audio.player
Class Player

java.lang.Object
  |
  +--mediaframe.mpeg1.audio.player.Player
All Implemented Interfaces:
java.lang.Runnable

public class Player
extends java.lang.Object
implements java.lang.Runnable

The Player class implements a simple player for playback of an MPEG audio stream.

Since:
0.0.8
Author:
Mat McGowan

Field Summary
private  MPEG1 _pech
          The reference to the video applet.
private static boolean _soundChecked
          True, if the audio device detection has been already done.
private static boolean _soundEnabled
          True, if the player has detected the suitable audio device for the current VM and able to play the sound.
private  boolean _stopped
          True, if the audio player is stopped.
private  AudioDevice audio
          The AudioDevice the audio samples are written to.
private  java.lang.Thread audio_thread
          The "Audio Decoder" thread object.
private  io_tool bitstream
          The MPEG audio bitstream.
private  mediaframe.mpeg1.audio.decoder.Crc16[] crc
          The 16-Bit CRC checksum of the MPEG audio bitstream.
private  mediaframe.mpeg1.audio.decoder.Decoder decoder
          The MPEG audio decoder.
private  mediaframe.mpeg1.audio.decoder.Header header
          The Audio header of the MPEG stream.
private  java.lang.Thread moribund
          The "Audio Decoder" thread that is being stopped.
 
Constructor Summary
Player(io_tool stream, MPEG1 pl)
          Creates a new Player instance with the specified MPEG audio bitstream and the reference to the video applet.
 
Method Summary
protected  boolean decodeFrame()
          Decodes a single frame.
static boolean isSoundEnabled()
          Returns true, if the player has detected the suitable audio device for the current VM and able to play the sound.
 boolean isStopped()
          Returns true, if the audio playback is stopped.
 void join()
          Waits until the audio process is dead.
 void pause()
          Pause the Audio Player.
 void play()
          Turns on audio output device.
 void run()
          Decodes the MPEG audio bitstream (calls in the loop the decodeFrame() method for each audio frame).
 void setMute(boolean mute)
          Sets the mute state of the audio player.
 void setVolume(float volume)
          Sets the volume (in the range 0..1) of the audio player.
 void start()
          Starts the "Audio Decoder" thread.
 void stop()
          Closes this player.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

bitstream

private io_tool bitstream
The MPEG audio bitstream.


decoder

private mediaframe.mpeg1.audio.decoder.Decoder decoder
The MPEG audio decoder.


audio

private AudioDevice audio
The AudioDevice the audio samples are written to.


header

private final mediaframe.mpeg1.audio.decoder.Header header
The Audio header of the MPEG stream.


crc

private mediaframe.mpeg1.audio.decoder.Crc16[] crc
The 16-Bit CRC checksum of the MPEG audio bitstream.


audio_thread

private volatile java.lang.Thread audio_thread
The "Audio Decoder" thread object.


_pech

private MPEG1 _pech
The reference to the video applet.


_stopped

private boolean _stopped
True, if the audio player is stopped.


_soundChecked

private static boolean _soundChecked
True, if the audio device detection has been already done.


_soundEnabled

private static boolean _soundEnabled
True, if the player has detected the suitable audio device for the current VM and able to play the sound.


moribund

private java.lang.Thread moribund
The "Audio Decoder" thread that is being stopped.

Constructor Detail

Player

public Player(io_tool stream,
              MPEG1 pl)
Creates a new Player instance with the specified MPEG audio bitstream and the reference to the video applet.

Parameters:
stream - the MPEG audio bitstream.
pl - the reference to the video applet.
Method Detail

start

public void start()
Starts the "Audio Decoder" thread.


run

public void run()
Decodes the MPEG audio bitstream (calls in the loop the decodeFrame() method for each audio frame). This method is called by the JRE after the "Audio Decoder" thread is started.

Specified by:
run in interface java.lang.Runnable

play

public void play()
Turns on audio output device.


stop

public void stop()
Closes this player. Any audio currently playing is stopped immediately.


join

public void join()
Waits until the audio process is dead.


pause

public void pause()
Pause the Audio Player.


decodeFrame

protected boolean decodeFrame()
                       throws mediaframe.mpeg1.audio.decoder.JavaLayerException,
                              java.lang.InterruptedException
Decodes a single frame.

Returns:
true if there are no more frames to decode, false otherwise.
Throws:
mediaframe.mpeg1.audio.decoder.JavaLayerException - if the decoder could not decode the audio frame.
java.lang.InterruptedException - if another process interrupts the current process.

isStopped

public boolean isStopped()
Returns true, if the audio playback is stopped.


setMute

public void setMute(boolean mute)
Sets the mute state of the audio player.

Parameters:
mute - the mute state (true, if the mute on and the player don't play the audio).

setVolume

public void setVolume(float volume)
Sets the volume (in the range 0..1) of the audio player.

Parameters:
volume - the volume to set.

isSoundEnabled

public static boolean isSoundEnabled()
Returns true, if the player has detected the suitable audio device for the current VM and able to play the sound.