public final class AudioPlayer extends java.lang.Thread implements AudioListener
Modifier and Type | Class and Description |
---|---|
(package private) static class |
AudioPlayer.Command |
(package private) class |
AudioPlayer.Execute
Passes information from the control thread to the playing thread
|
(package private) static class |
AudioPlayer.Result |
(package private) static class |
AudioPlayer.State |
Modifier and Type | Field and Description |
---|---|
private static AudioPlayer |
audioPlayer |
private AudioPlayer.Execute |
command |
private java.net.URL |
playingUrl |
private SoundPlayer |
soundPlayer |
private AudioPlayer.State |
state |
Modifier | Constructor and Description |
---|---|
private |
AudioPlayer() |
Modifier and Type | Method and Description |
---|---|
private static AudioPlayer |
getInstance()
Returns the singleton object, and if this is the first time, creates it along with
the thread to support audio
|
static void |
pause()
Pauses the currently playing audio stream.
|
static boolean |
paused()
Whether or not we are paused.
|
static void |
play(java.net.URL url)
Plays a WAV audio file from the beginning.
|
static void |
play(java.net.URL url,
double seconds)
Plays a WAV audio file from a specified position.
|
static void |
play(java.net.URL url,
double seconds,
double speed)
Plays a WAV audio file from a specified position at variable speed.
|
static boolean |
playing()
Whether or not we are playing.
|
void |
playing(java.net.URL playingURL)
Called when a new URL is being played.
|
static double |
position()
How far we are through playing, in seconds.
|
static void |
reset()
Resets the audio player.
|
void |
run()
Starts the thread to actually play the audio, per Thread interface
Not to be used as public, though Thread interface doesn't allow it to be made private
|
static double |
speed()
Speed at which we will play.
|
static java.net.URL |
url()
To get the Url of the playing or recently played audio.
|
activeCount, checkAccess, clone, 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
private static volatile AudioPlayer audioPlayer
private AudioPlayer.State state
private SoundPlayer soundPlayer
private java.net.URL playingUrl
private final AudioPlayer.Execute command
private AudioPlayer()
public static void play(java.net.URL url) throws java.lang.InterruptedException, java.io.IOException
url
- The resource to play, which must be a WAV file or streamjava.lang.InterruptedException
- thread interruptedjava.io.IOException
- audio fault exception, e.g. can't open stream, unhandleable audio formatpublic static void play(java.net.URL url, double seconds) throws java.lang.InterruptedException, java.io.IOException
url
- The resource to play, which must be a WAV file or streamseconds
- The number of seconds into the audio to start playingjava.lang.InterruptedException
- thread interruptedjava.io.IOException
- audio fault exception, e.g. can't open stream, unhandleable audio formatpublic static void play(java.net.URL url, double seconds, double speed) throws java.lang.InterruptedException, java.io.IOException
url
- The resource to play, which must be a WAV file or streamseconds
- The number of seconds into the audio to start playingspeed
- Rate at which audio playes (1.0 = real time, > 1 is faster)java.lang.InterruptedException
- thread interruptedjava.io.IOException
- audio fault exception, e.g. can't open stream, unhandleable audio formatpublic static void pause() throws java.lang.InterruptedException, java.io.IOException
java.lang.InterruptedException
- thread interruptedjava.io.IOException
- audio fault exception, e.g. can't open stream, unhandleable audio formatpublic static java.net.URL url()
public static boolean paused()
public static boolean playing()
public static double position()
public static double speed()
private static AudioPlayer getInstance()
public static void reset()
public void run()
run
in interface java.lang.Runnable
run
in class java.lang.Thread
public void playing(java.net.URL playingURL)
AudioListener
playing
in interface AudioListener
playingURL
- new URL being played