public class JOggPlayerListener extends Object implements Runnable
protected int runWithJOggPlayer(String[] cmdArgs) { int retVal = 1; JOggPlayerListener player_ = JOggPlayerListener.getInstance(); String piTunePath = ""; if(!"stop".equalsIgnoreCase(cmdArgs[0])) { piTunePath = "/mnt/nas/snd/ogg"+"/"+cmdArgs[1]; if (cmdArgs.length >1) { for (int i = 1; i < cmdArgs.length; i++) { piTunePath = piSndOggRootDir_+"/"+cmdArgs[i]; player_.addToPlaylist(piTunePath); } } player_.play_sound(); // this send the message to start the player thread and return here retVal = 0; } else // stop was called { // call stop player_.signalStopPlay(); } // because all the above calls send signals to JOggPlayerListener to execute in a separate Thread // they quickly return back here // so, we can do extra stuff here while we wait if(retVal==0) { System.out.println("\n waiting until song"+("tunes".equalsIgnoreCase(cmdArgs[0])?"s":"")+ " are done"); while(player_ != null && player_.isPlaying()) { ca.bc.webarts.widgets.Util.sleep(5*1000); System.out.print(player_.retrieveCurrentTunePlayTimeInMiliSeconds()/1000+ "("+ player_.retrieveTuneProgressRatio()+") "); } System.out.println("\nJOggPlayer is done."); } return retVal; }
JOggPlayerCommandline
that uses this class
Modifier and Type | Class and Description |
---|---|
(package private) class |
JOggPlayerListener.TimerThread
The thread that watches the time the song has been playing.
|
(package private) class |
JOggPlayerListener.UDPIO
Description of the Class
|
Modifier and Type | Field and Description |
---|---|
static String |
albumCoverURLBase_ |
(package private) byte[] |
buffer
Description of the Field
|
(package private) static int |
BUFFER_MULTIPLE
The File Load Buffer multiplier - the num kbites to take .
|
(package private) int |
bufferLengthInBytes
Description of the Field
|
(package private) static int |
BUFSIZE
The Play buffer size.
|
(package private) int |
bytes
current bytes being worked on.
|
(package private) int |
channels
Description of the Field
|
(package private) static byte[] |
convbuffer_
The pcm conversion buffer.
|
(package private) static int |
convsize_
the size (bytes) to allocate for the pcm conversion buffer.
|
(package private) int |
current_songDuration_ |
(package private) String |
current_source
Description of the Field
|
(package private) int |
currentPlaylistIndex_ |
(package private) Date |
date |
(package private) int |
debug_
Debug level. 0 is silent, 1 is error only; 2 is basic info, 3 is verbose, 4 is all
|
(package private) int |
frameSizeInBytes
Description of the Field
|
private static JOggPlayerListener |
INSTANCE
Singleton instance.
|
(package private) int |
left_vol_scale
Description of the Field
|
private boolean |
loopPaused_
Signals the playing loop to pause in a sleep loop until !
|
private boolean |
loopStopped_
Signals the playing loop to stop.
|
private int |
m_status |
(package private) Page |
og
Vorbis Ogg Data.
|
(package private) InputStream |
oggVorbisBitStream_
The Ogg Vorbis stream of data.
|
(package private) Packet |
op
Vorbis Ogg Data.
|
static int |
OPENED |
(package private) StreamState |
os
The JCraft JOgg StreamState.
|
(package private) SourceDataLine |
outputLine
Description of the Field
|
(package private) SyncState |
oy
The JCraft JOgg SyncState.
|
static int |
PAUSED |
(package private) Thread |
playerThread_
Description of the Field
|
static int |
PLAYING |
(package private) boolean |
playing_ |
Vector<String> |
playlist_
Description of the Field
|
(package private) String |
playlistfile
Description of the Field
|
(package private) boolean |
playonstartup
Description of the Field
|
(package private) int |
progressCount_
The bytes retrieved from current playing tune.
|
(package private) int |
rate
Description of the Field
|
(package private) int |
retry
Description of the Field
|
private int |
RETRY
Description of the Field
|
(package private) int |
right_vol_scale
Description of the Field
|
static int |
SEEKING |
private boolean |
shuffling_ |
private boolean |
signalNextInPlaylist_
Signals the playing loop to jump to next tune in playlist.
|
private boolean |
signalPreviousInPlaylist_
Signals the playing loop to jump to previous tune in playlist.
|
(package private) Vector<String> |
songComments_
Holds the current tune Vorbis Comments.
|
static int |
STOPPED |
(package private) boolean |
timerRunning_
Description of the Field
|
(package private) JOggPlayerListener.TimerThread |
timeWatcherThread_
Timer Thread.
|
(package private) String |
udp_baddress
Description of the Field
|
(package private) int |
udp_port
The (optional) UDP port to retrieve the Vorvis data FROM.
|
static int |
UNKNOWN
These variables are used to distinguish stopped, paused, playing states.
|
(package private) Block |
vb
Vorbis Ogg Data.
|
(package private) Comment |
vc
The currently being read Vorbis Comment.
|
(package private) DspState |
vd
Vorbis Ogg Data.
|
(package private) Info |
vi
Vorbis Ogg Data.
|
Modifier | Constructor and Description |
---|---|
private |
JOggPlayerListener()
Private constructor for Singleton instance.
|
Modifier and Type | Method and Description |
---|---|
void |
addDirFilesToPlaylist(String dirPath)
Recursively Adds multiple directories of *.ogg files to the playlist.
|
void |
addDirFilesToPlaylist(String[] dirPaths)
Recursively Adds multiple directories of *.ogg files to the playlist.
|
void |
addDirFilesToPlaylist(String[] dirPaths,
boolean recurseSubDirs)
Adds multiple directories of *.ogg files to the playlist.
|
void |
addDirFilesToPlaylist(String[] dirPaths,
boolean recurseSubDirs,
boolean sortFilenames)
Add multiple directories of *.ogg files to the playlist.
|
void |
addDirFilesToPlaylist(String dirPath,
boolean recurseSubDirs)
Recursively Adds multiple directories of *.ogg files to the playlist.
|
void |
addToPlaylist(String tunePath)
Add a single tune paths to the playlist.
|
void |
addToPlaylist(String[] tunePaths)
Add multiple tune paths to the playlist.
|
void |
clearPlaylist()
Description of the Method
|
void |
clearPlaylistSignals()
Threadsafe Clears ALL thread signals for the playlist playing.
|
void |
clearStopSignal()
Threadsafe Sets loopStopped_backto false after successfull stop.
|
(package private) String |
fetch_m3u(String m3u)
Description of the Method
|
(package private) String |
fetch_pls(String pls)
Description of the Method
|
String |
getAlbumCoverURL() |
String |
getAlbumCoverURL(int playListIndex)
Gets the Album Cover URL of the current item in the playlist.
|
String |
getAlbumName()
Gets the Album Name of the passed in playlistItem in the playlist.
|
String |
getAlbumName(int playListIndex)
Gets the Album Name of the passed in playListIndex in the playlist.
|
String |
getAlbumName(int playListIndex,
boolean capsToSpaces)
Gets the Album Name of the passed in playListIndex in the playlist.
|
int |
getAlbumTrackNum()
Gets the album TrackNum of the current item in the playlist.
|
int |
getAlbumTrackNum(int playListIndex)
Gets the album TrackNum of the passed in playListIndex in the playlist.
|
String |
getArtistName()
Gets the Artist name of the current item in the playlist.
|
String |
getArtistName(int playListIndex)
Gets the Artist name of the passed in playListIndex in the playlist.
|
String |
getArtistName(int playListIndex,
boolean capsToSpaces)
Gets the Artist name of the passed in playListIndex in the playlist.
|
int |
getCurrentPlaylistIndex()
Threadsafe Get Method for class var currentPlaylistIndex_.
|
String |
getFilename()
Gets the Filename of the current item in the playlist.
|
String |
getFilename(int playListIndex)
Gets the Filename of the specified item in the playlist.
|
Vector<String> |
getIndexedPlaylistArtistAlbumSongnames(boolean addIndex) |
static JOggPlayerListener |
getInstance()
Singleton instance getter.
|
boolean |
getLoopPaused()
Threadsafe Get Method for class field 'loopPaused_'.
|
boolean |
getLoopStopped()
Threadsafe Get method for class var loopStopped_.
|
(package private) SourceDataLine |
getOutputLine(int channels,
int rate)
Gets the outputLine attribute of the JOggPlayerListener object
|
Vector<String> |
getPlaylistArtistAlbumSongnames() |
int |
getPlaylistSize()
Threadsafe Get Method for class var currentPlaylistIndex_.
|
boolean |
getShuffling()
Get Method for class field 'shuffling_'.
|
boolean |
getSignalNextInPlaylist()
Threadsafe Get Method for class var signalNextInPlaylist_.
|
boolean |
getSignalPreviousInPlaylist()
Threadsafe Get Method for class var signalPreviousInPlaylist_.
|
Vector<String> |
getSongComments()
Get Method for class field 'songComments_'.
|
String |
getSongName()
Gets the Song name of the current item in the playlist.
|
String |
getSongName(int playListIndex)
Gets the Song name of the passed in playListIndex in the playlist.
|
int |
getStatus() |
String |
getTitle()
Gets the title of the current item in the playlist.
|
String |
getTitle(int playListIndex)
Gets the title of the specified item in the playlist.
|
(package private) void |
init_audio(int channels,
int rate)
Description of the Method
|
(package private) void |
init_jorbis()
instantaites all the JOgg streams and states.
|
boolean |
isPaused() |
boolean |
isPlaying() |
boolean |
isStopped() |
protected void |
pausePlayback()
Pauses the playback.
|
void |
play_current_sound()
Starts the playing from current index in the playlist.
|
void |
play_sound()
Starts the playing from index 0 in the playlist.
|
void |
play_sound(int playListIndex)
Start playing a tune from the playlist starting from the index passed in as a parameter playListIndex.
|
private void |
play_stream()
Converts the raw Vorbis data int music!
|
private void |
play_udp_stream(Thread me)
Description of the Method
|
private int |
readFromStream(byte[] buffer,
int index,
int BUFSIZE)
Reads from the oggVorbisBitStream_ a specified number of Bytes(BUFSIZE) worth
sarting at index and puts them in the specified buffer[].
|
private String |
readline(InputStream is)
Description of the Method
|
private void |
reStartTimer() |
protected void |
resumePlayback()
Resumes the playback.
|
int |
retrieveCurrentTunePlayTimeInMiliSeconds() |
int |
retrieveSongDurationInMiliSeconds() |
int |
retrieveTuneProgressRatio() |
void |
run()
The Runnable to do the actual playing of the song.
|
(package private) InputStream |
selectSource(String item)
turns a named item into its InputStream.
|
void |
setLoopPaused(boolean loopPaused)
Threadsafe Set Method for class field 'loopPaused_'.
|
void |
setShuffling(boolean shuffling)
Set Method for class field 'shuffling_'.
|
void |
setSongComments(Vector<String> songComments)
Set Method for class field 'songComments_'.
|
void |
signalLoopPaused()
Threadsafe Send a signal to toggle the paused state of the loop playing.
|
void |
signalNextInPlaylist()
signal the current play to jump to next in playlist.
|
void |
signalPreviousInPlaylist()
Threadsafe signal the current play to jump to previous in playlist.
|
void |
signalStopPlay()
Threadsafe signal the current play to STOP.
|
void |
start()
Description of the Method
|
private void |
startTimer()
Helper method to encapsulate the starting of the timeWatcherRunnable_
|
void |
stop_sound()
Stops play
|
void |
stop()
Stop the playback
Player Status = STOPPED.
|
protected void |
togglePause() |
int debug_
static final int BUFFER_MULTIPLE
static final int BUFSIZE
static int convsize_
static byte[] convbuffer_
private int RETRY
int retry
InputStream oggVorbisBitStream_
int udp_port
String udp_baddress
String playlistfile
StreamState os
Vector<String> songComments_
byte[] buffer
int bytes
int rate
int channels
int left_vol_scale
int right_vol_scale
SourceDataLine outputLine
String current_source
int current_songDuration_
int frameSizeInBytes
int bufferLengthInBytes
boolean playonstartup
boolean playing_
private boolean signalNextInPlaylist_
private boolean signalPreviousInPlaylist_
private boolean loopPaused_
private boolean loopStopped_
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
private int m_status
boolean timerRunning_
int progressCount_
public static String albumCoverURLBase_
JOggPlayerListener.TimerThread timeWatcherThread_
startTimer
method to init and start the timer.int currentPlaylistIndex_
private boolean shuffling_
Thread playerThread_
private static JOggPlayerListener INSTANCE
private JOggPlayerListener()
public static JOggPlayerListener getInstance()
public void start()
private int readFromStream(byte[] buffer, int index, int BUFSIZE)
buffer
- the byteBuffer holding the read in dataindex
- where to start reading from the stringBUFSIZE
- the max number of bytes to readprivate void startTimer()
private void reStartTimer()
public int retrieveCurrentTunePlayTimeInMiliSeconds()
public int retrieveTuneProgressRatio()
public int retrieveSongDurationInMiliSeconds()
public int getStatus()
public boolean isPaused()
public boolean isPlaying()
public boolean isStopped()
public void setSongComments(Vector<String> songComments)
songComments
- is the value to set this class field to.public Vector<String> getSongComments()
public void run()
public void signalStopPlay()
public void clearStopSignal()
public Vector<String> getPlaylistArtistAlbumSongnames()
public Vector<String> getIndexedPlaylistArtistAlbumSongnames(boolean addIndex)
public int getCurrentPlaylistIndex()
public int getPlaylistSize()
public void signalNextInPlaylist()
public boolean getSignalNextInPlaylist()
public void signalPreviousInPlaylist()
public boolean getSignalPreviousInPlaylist()
public void setShuffling(boolean shuffling)
shuffling
- is the value to set this class field to.public boolean getShuffling()
public void clearPlaylistSignals()
protected void togglePause()
protected void pausePlayback()
protected void resumePlayback()
public void signalLoopPaused()
public void setLoopPaused(boolean loopPaused)
loopPaused
- is the value to set this class field to.public boolean getLoopPaused()
public boolean getLoopStopped()
public String getFilename()
public String getFilename(int playListIndex)
playlistItem
- the item to get name forpublic String getTitle()
public String getTitle(int playListIndex)
playlistItem
- the item to get name forpublic String getAlbumCoverURL()
public String getAlbumCoverURL(int playListIndex)
public String getArtistName()
public String getArtistName(int playListIndex)
public String getArtistName(int playListIndex, boolean capsToSpaces)
public String getSongName()
public String getSongName(int playListIndex)
public String getAlbumName()
public String getAlbumName(int playListIndex)
public String getAlbumName(int playListIndex, boolean capsToSpaces)
public int getAlbumTrackNum()
public int getAlbumTrackNum(int playListIndex)
public void play_sound()
public void play_current_sound()
public void play_sound(int playListIndex)
playListIndex
- is the tune to start playingpublic void stop()
public void stop_sound()
void init_jorbis()
SourceDataLine getOutputLine(int channels, int rate)
channels
- Description of the Parameterrate
- Description of the Parametervoid init_audio(int channels, int rate)
channels
- Description of the Parameterrate
- Description of the ParameterInputStream selectSource(String item)
item
- Description of the ParameterString fetch_pls(String pls)
pls
- Description of the ParameterString fetch_m3u(String m3u)
m3u
- Description of the Parameterpublic void addToPlaylist(String tunePath)
tunePath
- is the path the the tune to add to the playlistpublic void addToPlaylist(String[] tunePaths)
tunePaths
- is the array of paths for the tunes to add to the playlistpublic void addDirFilesToPlaylist(String dirPath)
dirPath
- is the directory path for the tunes to add to the playlistpublic void addDirFilesToPlaylist(String dirPath, boolean recurseSubDirs)
dirPath
- is the directory path for the tunes to add to the playlistrecurseSubDirs
- recurseall sub-dirs while processingpublic void addDirFilesToPlaylist(String[] dirPaths)
dirPaths
- is the array of directory paths for the tunes to add to the playlistpublic void addDirFilesToPlaylist(String[] dirPaths, boolean recurseSubDirs)
dirPaths
- is the array of directory paths for the tunes to add to the playlistrecurseSubDirs
- choose to recurse subDirs for *.ogg filespublic void addDirFilesToPlaylist(String[] dirPaths, boolean recurseSubDirs, boolean sortFilenames)
dirPaths
- is the array of directory paths for the tunes to add to the playlistrecurseSubDirs
- choose to recurse subDirs for *.ogg filessortFilenames
- choose to sort the *.ogg files as they go into playlist_public void clearPlaylist()
private void play_stream()
private void play_udp_stream(Thread me)
me
- Description of the Parameterprivate String readline(InputStream is)
is
- Description of the ParameterWebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses