javazoom.jlgui.basicplayer
Class BasicPlayer

java.lang.Object
  extended by javazoom.jlgui.basicplayer.BasicPlayer
All Implemented Interfaces:
java.lang.Runnable, BasicController

public class BasicPlayer
extends java.lang.Object
implements BasicController, java.lang.Runnable

BasicPlayer is a threaded simple player class based on JavaSound API. It has been successfully tested under J2SE 1.3.x, 1.4.x and 1.5.0 beta.


Field Summary
static int EXTERNAL_BUFFER_SIZE
           
static int OPENED
           
static int PAUSED
           
static int PLAYING
           
static int SEEKING
           
static int SKIP_INACCURACY_SIZE
           
static int STOPPED
           
static int UNKNOWN
          These variables are used to distinguish stopped, paused, playing states.
 
Constructor Summary
BasicPlayer()
          Constructs a Basic Player.
 
Method Summary
 void addBasicPlayerListener(BasicPlayerListener bpl)
          Add listener to be notified.
 float getGainValue()
          Returns Gain value.
 int getLineBufferSize()
          Return SourceDataLine buffer size.
 java.util.Collection getListeners()
          Return registered listeners.
 float getMaximumGain()
          Gets max Gain value.
 float getMinimumGain()
          Gets min Gain value.
 float getPan()
          Returns Pan value.
 float getPrecision()
          Returns Pan precision.
 long getSleepTime()
          Return thread sleep time in milliseconds.
 int getStatus()
          Returns BasicPlayer status.
 boolean hasGainControl()
          Returns true if Gain control is supported.
 boolean hasPanControl()
          Returns true if Pan control is supported.
 void open(AudioSample sample)
          Open an AudioSample from the JMotocher-Project
 void open(java.io.File file)
          Open file to play.
 void open(java.io.InputStream inputStream)
          Open inputstream to play.
 void open(java.net.URL url)
          Open URL to play.
 void pause()
          Pause playback.
 void play()
          Start playback.
 void removeBasicPlayerListener(BasicPlayerListener bpl)
          Remove registered listener.
 void resume()
          Resume playback.
 void run()
          Main loop.
 long seek(long bytes)
          Skip bytes.
 void setGain(double fGain)
          Sets Gain value.
 void setLineBufferSize(int size)
          Set SourceDataLine buffer size.
 void setPan(double fPan)
          Sets Pan value.
 void setSleepTime(long time)
          Set thread sleep time.
 void stop()
          Stop playback.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EXTERNAL_BUFFER_SIZE

public static int EXTERNAL_BUFFER_SIZE

SKIP_INACCURACY_SIZE

public static int SKIP_INACCURACY_SIZE

UNKNOWN

public static final int UNKNOWN
These variables are used to distinguish stopped, paused, playing states. We need them to control Thread.

See Also:
Constant Field Values

PLAYING

public static final int PLAYING
See Also:
Constant Field Values

PAUSED

public static final int PAUSED
See Also:
Constant Field Values

STOPPED

public static final int STOPPED
See Also:
Constant Field Values

OPENED

public static final int OPENED
See Also:
Constant Field Values

SEEKING

public static final int SEEKING
See Also:
Constant Field Values
Constructor Detail

BasicPlayer

public BasicPlayer()
Constructs a Basic Player.

Method Detail

addBasicPlayerListener

public void addBasicPlayerListener(BasicPlayerListener bpl)
Add listener to be notified.

Parameters:
bpl -

getListeners

public java.util.Collection getListeners()
Return registered listeners.

Returns:

removeBasicPlayerListener

public void removeBasicPlayerListener(BasicPlayerListener bpl)
Remove registered listener.

Parameters:
bpl -

setLineBufferSize

public void setLineBufferSize(int size)
Set SourceDataLine buffer size. It affects audio latency. (the delay between line.write(data) and real sound). Minimum value should be over 10000 bytes.

Parameters:
size - -1 means maximum buffer size available.

getLineBufferSize

public int getLineBufferSize()
Return SourceDataLine buffer size.

Returns:
-1 maximum buffer size.

setSleepTime

public void setSleepTime(long time)
Set thread sleep time. Default is -1 (no sleep time).

Parameters:
time - in milliseconds.

getSleepTime

public long getSleepTime()
Return thread sleep time in milliseconds.

Returns:
-1 means no sleep time.

getStatus

public int getStatus()
Returns BasicPlayer status.

Returns:
status

open

public void open(AudioSample sample)
          throws BasicPlayerException
Open an AudioSample from the JMotocher-Project

Throws:
BasicPlayerException

open

public void open(java.io.File file)
          throws BasicPlayerException
Open file to play.

Specified by:
open in interface BasicController
Throws:
BasicPlayerException

open

public void open(java.net.URL url)
          throws BasicPlayerException
Open URL to play.

Specified by:
open in interface BasicController
Throws:
BasicPlayerException

open

public void open(java.io.InputStream inputStream)
          throws BasicPlayerException
Open inputstream to play.

Specified by:
open in interface BasicController
Throws:
BasicPlayerException

run

public void run()
Main loop. Player Status == STOPPED || SEEKING => End of Thread + Freeing Audio Ressources.
Player Status == PLAYING => Audio stream data sent to Audio line.
Player Status == PAUSED => Waiting for another status.

Specified by:
run in interface java.lang.Runnable

hasGainControl

public boolean hasGainControl()
Returns true if Gain control is supported.


getGainValue

public float getGainValue()
Returns Gain value.


getMaximumGain

public float getMaximumGain()
Gets max Gain value.


getMinimumGain

public float getMinimumGain()
Gets min Gain value.


hasPanControl

public boolean hasPanControl()
Returns true if Pan control is supported.


getPrecision

public float getPrecision()
Returns Pan precision.


getPan

public float getPan()
Returns Pan value.


seek

public long seek(long bytes)
          throws BasicPlayerException
Description copied from interface: BasicController
Skip bytes.

Specified by:
seek in interface BasicController
Returns:
bytes skipped according to audio frames constraint.
Throws:
BasicPlayerException
See Also:
BasicController.seek(long)

play

public void play()
          throws BasicPlayerException
Description copied from interface: BasicController
Start playback.

Specified by:
play in interface BasicController
Throws:
BasicPlayerException
See Also:
BasicController.play()

stop

public void stop()
          throws BasicPlayerException
Description copied from interface: BasicController
Stop playback.

Specified by:
stop in interface BasicController
Throws:
BasicPlayerException
See Also:
BasicController.stop()

pause

public void pause()
           throws BasicPlayerException
Description copied from interface: BasicController
Pause playback.

Specified by:
pause in interface BasicController
Throws:
BasicPlayerException
See Also:
BasicController.pause()

resume

public void resume()
            throws BasicPlayerException
Description copied from interface: BasicController
Resume playback.

Specified by:
resume in interface BasicController
Throws:
BasicPlayerException
See Also:
BasicController.resume()

setPan

public void setPan(double fPan)
            throws BasicPlayerException
Sets Pan value. Line should be opened before calling this method. Linear scale : -1.0 <--> +1.0

Specified by:
setPan in interface BasicController
Parameters:
fPan - value from -1.0 to +1.0
Throws:
BasicPlayerException

setGain

public void setGain(double fGain)
             throws BasicPlayerException
Sets Gain value. Line should be opened before calling this method. Linear scale 0.0 <--> 1.0 Threshold Coef. : 1/2 to avoid saturation.

Specified by:
setGain in interface BasicController
Parameters:
fGain - value from 0.0 to 1.0
Throws:
BasicPlayerException