|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectjava.lang.Thread
com.lightdev.lib.audio.Player
public class Player
Audio player for MP3 files
Using this class requires the MP3 decoder plug-in at http://www.tritonus.org/plugins.html or another component that implements the Java Sound API.
Class Player only plays audio when no PlayerListener
is registered or when none of the registered listeners signals the player that
it consumes decoded bytes. When a listener signals the player that it consumes
decoded bytes, the player does not play audio, it only passes decoded bytes
to the listener. The listener is responsible to pass decoded bytes back to the
player with a call to method Player.write() to actually
play audio.
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class java.lang.Thread |
|---|
Thread.State, Thread.UncaughtExceptionHandler |
| Field Summary | |
|---|---|
static int |
INITIALIZING
constant value for status initializing (i.e. not ready to play yet) |
static int |
NONE
constant value to indicate that no status has been set so far |
static int |
PAUSED
constant value for status paused (i.e. thread still active, can resume play) |
static int |
PLAYING
constant value for status playing |
static int |
READY
constant value for status ready to play |
static int |
SKIPPING
constant value to indicate that the player currently repositions by skipping a given amount of bytes |
static int |
STOPPED_EOM
constant value for status stopped due to end of media (thread will terminate irrevocably immediately after) |
static int |
STOPPED_PLAY
constant value for status stopped during play (thread will terminate irrevocably immediately after) |
static int |
TERMINATED
constant value for a terminated thread |
| Fields inherited from class java.lang.Thread |
|---|
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
| Constructor Summary | |
|---|---|
Player()
constructor |
|
| Method Summary | |
|---|---|
void |
addPlayerListener(PlayerListener l)
add a PlayerListener to this Player thread |
String |
getAlbum()
get the album of the currently playing song |
String |
getArtist()
get the artist of the currently playing song |
float |
getAudioFrameRate()
get the number of frames per second for this audio input stream |
float |
getBalance()
get the balance |
int |
getChannels()
get the number of channels for this audio input stream |
long |
getDuration()
get the duration of the currently playing song |
int |
getFrameCount()
get the frame count |
double |
getFrameRate()
get the frame rate |
int |
getFrameSize()
get the size of a frame in bytes |
float |
getSampleRate()
get the number of samples per second |
int |
getSampleSizeInBits()
get the size of one sample in bits |
long |
getSizeBytes()
get the length of the file in bytes |
SourceDataLine |
getSourceDataLine()
get the SourceDataLine of this Player |
String |
getTitle()
get the title of the currently playing song |
float |
getVolume()
get the volume |
boolean |
isBigEndian()
dtermine wether or not this audio input stream is big endian |
boolean |
isPaused()
determine whether or not this Player is paused |
void |
pausePlay()
pause playing Keeps this instance of Player thread running
(sleeping until it is resumed or stopped, that is) |
void |
removePlayerListener(PlayerListener l)
remove a PlayerListener from this Player thread |
void |
resumePlay()
resume playing a paused play |
void |
run()
run this thread, i.e. play an audio file Don't use this method directly, use startPlay instead |
void |
setBalance(float balance)
set the balance of this player to a value of -100 (left) and 100 (right); 0 means equal distribution between left and right |
void |
setStatus(int newStatus)
set the status of this Player object to a given new status |
void |
setVolume(float vol,
float correction)
set the volume of this player to a value between 0 (sound off) and 100 percent. |
void |
startPlay(File file)
start to play a given audio file |
void |
startPlay(File file,
long startPos)
start to play a given audio file at a certain position |
void |
stopPlay()
stop playing Will terminate this instance of Player thread without
the possibility to restart it. |
void |
write(byte[] abData,
int nBytes)
write some audio bytes to the source data line of this player |
| Methods inherited from class java.lang.Thread |
|---|
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final int NONE
public static final int INITIALIZING
public static final int SKIPPING
public static final int READY
public static final int PLAYING
public static final int PAUSED
public static final int STOPPED_PLAY
public static final int STOPPED_EOM
public static final int TERMINATED
| Constructor Detail |
|---|
public Player()
| Method Detail |
|---|
public void startPlay(File file)
file - File the audio file to playpublic SourceDataLine getSourceDataLine()
SourceDataLine of this Player
- Returns:
- the SourceDataLine, if any
public void startPlay(File file,
long startPos)
file - File the audio file to start to playstartPos - long the byte position to start playing atpublic void stopPlay()
Will terminate this instance of Player thread without
the possibility to restart it.
public void pausePlay()
Keeps this instance of Player thread running
(sleeping until it is resumed or stopped, that is)
resumePlaypublic void resumePlay()
pausePlaypublic void setStatus(int newStatus)
newStatus - int the new status to set this player to
public void setVolume(float vol,
float correction)
vol - floatcorrection - float value to add to skip non hearable regionpublic float getVolume()
public void setBalance(float balance)
balance - floatpublic float getBalance()
public long getDuration()
public String getTitle()
public String getArtist()
public String getAlbum()
public int getFrameCount()
public double getFrameRate()
public long getSizeBytes()
public int getSampleSizeInBits()
public int getFrameSize()
public float getAudioFrameRate()
public float getSampleRate()
public boolean isBigEndian()
public int getChannels()
public void write(byte[] abData,
int nBytes)
abData - byte[] byte buffer having bytes to writenBytes - int the number of bytes from abData to write outpublic boolean isPaused()
Player is paused
public void run()
Don't use this method directly, use startPlay instead
run in interface Runnablerun in class ThreadPlayer.startPlay()public void addPlayerListener(PlayerListener l)
PlayerListener to this Player thread
l - PlayerListener the listener to addpublic void removePlayerListener(PlayerListener l)
PlayerListener from this Player thread
l - PlayerListener the listener to remove
|
Copyright (c) 2004, 2005 Ulrich Hilger | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||