javazoom.jl.player
Class AudioDeviceBase

java.lang.Object
  extended by javazoom.jl.player.AudioDeviceBase
All Implemented Interfaces:
AudioDevice
Direct Known Subclasses:
JavaSoundAudioDevice, NullAudioDevice

public abstract class AudioDeviceBase
extends java.lang.Object
implements AudioDevice

The AudioDeviceBase class provides a simple thread-safe implementation of the AudioDevice interface. Template methods are provided for subclasses to override and in doing so provide the implementation for the main operations of the AudioDevice interface.

Since:
0.0.8

Constructor Summary
AudioDeviceBase()
           
 
Method Summary
 void close()
          Closes this audio device.
protected  void closeImpl()
          Template method to provide the implementation for closing the audio device.
 void flush()
          Waits for any buffered audio samples to be played by the audio device.
protected  void flushImpl()
          Template method to provide the implementation for flushing any buffered audio data.
protected  Decoder getDecoder()
          Retrieves the decoder that provides audio data to this audio device.
 boolean isOpen()
          Determines if this audio device is open or not.
 void open(Decoder decoder)
          Opens this audio device.
protected  void openImpl()
          Template method to provide the implementation for the opening of the audio device.
protected  void setOpen(boolean open)
          Sets the open state for this audio device.
 void write(short[] samples, int offs, int len)
          Writes audio data to this audio device.
protected  void writeImpl(short[] samples, int offs, int len)
          Template method to provide the implementation for writing audio samples to the audio device.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javazoom.jl.player.AudioDevice
getPosition
 

Constructor Detail

AudioDeviceBase

public AudioDeviceBase()
Method Detail

open

public void open(Decoder decoder)
          throws JavaLayerException
Opens this audio device.

Specified by:
open in interface AudioDevice
Parameters:
decoder - The decoder that will provide audio data to this audio device.
Throws:
JavaLayerException

openImpl

protected void openImpl()
                 throws JavaLayerException
Template method to provide the implementation for the opening of the audio device.

Throws:
JavaLayerException

setOpen

protected void setOpen(boolean open)
Sets the open state for this audio device.


isOpen

public boolean isOpen()
Determines if this audio device is open or not.

Specified by:
isOpen in interface AudioDevice
Returns:
true if the audio device is open, false if it is not.

close

public void close()
Closes this audio device. If the device is currently playing audio, playback is stopped immediately without flushing any buffered audio data.

Specified by:
close in interface AudioDevice

closeImpl

protected void closeImpl()
Template method to provide the implementation for closing the audio device.


write

public void write(short[] samples,
                  int offs,
                  int len)
           throws JavaLayerException
Writes audio data to this audio device. Audio data is assumed to be in the output format of the decoder. This method may return before the data has actually been sounded by the device if the device buffers audio samples.

Specified by:
write in interface AudioDevice
Parameters:
samples - The samples to write to the audio device.
offs - The offset into the array of the first sample to write.
len - The number of samples from the array to write.
Throws:
JavaLayerException - if the audio data could not be written to the audio device. If the audio device is not open, this method does nthing.

writeImpl

protected void writeImpl(short[] samples,
                         int offs,
                         int len)
                  throws JavaLayerException
Template method to provide the implementation for writing audio samples to the audio device.

Throws:
JavaLayerException

flush

public void flush()
Waits for any buffered audio samples to be played by the audio device. This method should only be called prior to closing the device.

Specified by:
flush in interface AudioDevice

flushImpl

protected void flushImpl()
Template method to provide the implementation for flushing any buffered audio data.


getDecoder

protected Decoder getDecoder()
Retrieves the decoder that provides audio data to this audio device.

Returns:
The associated decoder.


JavaZOOM 1999-2008