public class BasicPlayer extends Object implements BasicController, Runnable
| Modifier and Type | Field and Description |
|---|---|
protected int |
encodedLength |
static int |
EXTERNAL_BUFFER_SIZE |
protected AudioFileFormat |
m_audioFileFormat |
protected AudioInputStream |
m_audioInputStream |
protected Object |
m_dataSource |
protected AudioInputStream |
m_encodedaudioInputStream |
protected FloatControl |
m_gainControl |
protected SourceDataLine |
m_line |
protected String |
m_mixerName |
protected FloatControl |
m_panControl |
protected Thread |
m_thread |
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 and Description |
|---|
BasicPlayer()
Constructs a Basic Player.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addBasicPlayerListener(BasicPlayerListener bpl)
Add listener to be notified.
|
protected void |
closeStream() |
protected void |
createLine()
Inits a DateLine.
We check if the line supports Gain and Pan controls. |
protected Map |
deepCopy(Map src)
Deep copy of a Map.
|
protected int |
getEncodedStreamPosition() |
float |
getGainValue()
Returns Gain value.
|
int |
getLineBufferSize()
Return SourceDataLine buffer size.
|
int |
getLineCurrentBufferSize()
Return SourceDataLine current buffer size.
|
Collection |
getListeners()
Return registered listeners.
|
float |
getMaximumGain()
Gets max Gain value.
|
float |
getMinimumGain()
Gets min Gain value.
|
Mixer |
getMixer(String name) |
String |
getMixerName() |
List |
getMixers() |
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.
|
protected void |
initAudioInputStream()
Inits AudioInputStream and AudioFileFormat from the data source.
|
protected void |
initAudioInputStream(File file)
Inits Audio ressources from file.
|
protected void |
initAudioInputStream(InputStream inputStream)
Inits Audio ressources from InputStream.
|
protected void |
initAudioInputStream(URL url)
Inits Audio ressources from URL.
|
protected void |
initLine()
Inits Audio ressources from AudioSystem.
|
protected void |
notifyEvent(int code,
int position,
double value,
Object description)
Notify listeners about a BasicPlayerEvent.
|
void |
open(File file)
Open file to play.
|
void |
open(InputStream inputStream)
Open inputstream to play.
|
void |
open(URL url)
Open URL to play.
|
protected void |
openLine()
Opens the line.
|
void |
pause()
Pause playback.
|
protected void |
pausePlayback()
Pauses the playback.
Player Status = PAUSED. |
void |
play()
Start playback.
|
void |
removeBasicPlayerListener(BasicPlayerListener bpl)
Remove registered listener.
|
protected void |
reset() |
void |
resume()
Resume playback.
|
protected void |
resumePlayback()
Resumes the playback.
Player Status = PLAYING. |
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 |
setMixerName(String name) |
void |
setPan(double fPan)
Sets Pan value.
|
void |
setSleepTime(long time)
Set thread sleep time.
|
protected long |
skipBytes(long bytes)
Skip bytes in the File inputstream.
|
protected void |
startPlayback()
Starts playback.
|
void |
stop()
Stop playback.
|
protected void |
stopPlayback()
Stops the playback.
Player Status = STOPPED. Thread should free Audio ressources. |
public static int EXTERNAL_BUFFER_SIZE
public static int SKIP_INACCURACY_SIZE
protected Thread m_thread
protected Object m_dataSource
protected AudioInputStream m_encodedaudioInputStream
protected int encodedLength
protected AudioInputStream m_audioInputStream
protected AudioFileFormat m_audioFileFormat
protected SourceDataLine m_line
protected FloatControl m_gainControl
protected FloatControl m_panControl
protected String m_mixerName
public static final int UNKNOWN
public static final int PLAYING
public static final int PAUSED
public static final int STOPPED
public static final int OPENED
public static final int SEEKING
protected void reset()
public void addBasicPlayerListener(BasicPlayerListener bpl)
bpl - public Collection getListeners()
public void removeBasicPlayerListener(BasicPlayerListener bpl)
bpl - public void setLineBufferSize(int size)
size - -1 means maximum buffer size available.public int getLineBufferSize()
public int getLineCurrentBufferSize()
public void setSleepTime(long time)
time - in milliseconds.public long getSleepTime()
public int getStatus()
public void open(File file) throws BasicPlayerException
open in interface BasicControllerBasicPlayerExceptionpublic void open(URL url) throws BasicPlayerException
open in interface BasicControllerBasicPlayerExceptionpublic void open(InputStream inputStream) throws BasicPlayerException
open in interface BasicControllerBasicPlayerExceptionprotected void initAudioInputStream()
throws BasicPlayerException
BasicPlayerExceptionprotected void initAudioInputStream(File file) throws UnsupportedAudioFileException, IOException
protected void initAudioInputStream(URL url) throws UnsupportedAudioFileException, IOException
protected void initAudioInputStream(InputStream inputStream) throws UnsupportedAudioFileException, IOException
protected void initLine()
throws LineUnavailableException
LineUnavailableExceptionprotected void createLine()
throws LineUnavailableException
LineUnavailableExceptionprotected void openLine()
throws LineUnavailableException
LineUnavailableExceptionprotected void stopPlayback()
protected void pausePlayback()
protected void resumePlayback()
protected void startPlayback()
throws BasicPlayerException
BasicPlayerExceptionpublic void run()
protected long skipBytes(long bytes)
throws BasicPlayerException
bytes - BasicPlayerExceptionprotected void notifyEvent(int code,
int position,
double value,
Object description)
code - event code.position - in the stream when the event occurs.protected int getEncodedStreamPosition()
protected void closeStream()
public boolean hasGainControl()
public float getGainValue()
public float getMaximumGain()
public float getMinimumGain()
public boolean hasPanControl()
public float getPrecision()
public float getPan()
public long seek(long bytes)
throws BasicPlayerException
BasicControllerseek in interface BasicControllerBasicPlayerExceptionBasicController.seek(long)public void play()
throws BasicPlayerException
BasicControllerplay in interface BasicControllerBasicPlayerExceptionBasicController.play()public void stop()
throws BasicPlayerException
BasicControllerstop in interface BasicControllerBasicPlayerExceptionBasicController.stop()public void pause()
throws BasicPlayerException
BasicControllerpause in interface BasicControllerBasicPlayerExceptionBasicController.pause()public void resume()
throws BasicPlayerException
BasicControllerresume in interface BasicControllerBasicPlayerExceptionBasicController.resume()public void setPan(double fPan)
throws BasicPlayerException
setPan in interface BasicControllerfPan - value from -1.0 to +1.0BasicPlayerExceptionpublic void setGain(double fGain)
throws BasicPlayerException
setGain in interface BasicControllerfGain - value from 0.0 to 1.0BasicPlayerExceptionpublic List getMixers()
public String getMixerName()
public void setMixerName(String name)
Copyright © 2016. All Rights Reserved.