public final class AudioPlayer extends java.lang.Thread
Modifier and Type | Class and Description |
---|---|
private static class |
AudioPlayer.Command |
private class |
AudioPlayer.Execute
Passes information from the control thread to the playing thread
|
private static class |
AudioPlayer.Result |
private static class |
AudioPlayer.State |
Modifier and Type | Field and Description |
---|---|
private static AudioPlayer |
audioPlayer |
private double |
bytesPerSecond |
private double |
calibration |
private static long |
chunk |
private AudioPlayer.Execute |
command |
private double |
leadIn |
private java.net.URL |
playingUrl |
private double |
position |
private double |
speed |
private AudioPlayer.State |
state |
Modifier | Constructor and Description |
---|---|
private |
AudioPlayer() |
Modifier and Type | Method and Description |
---|---|
static void |
audioMalfunction(java.lang.Exception ex)
Shows a popup audio error message for the given exception.
|
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.
|
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 java.net.URL playingUrl
private double leadIn
private double calibration
private double position
private double bytesPerSecond
private static long chunk
private double speed
private AudioPlayer.Execute command
private AudioPlayer()
public static void play(java.net.URL url) throws java.lang.Exception
url
- The resource to play, which must be a WAV file or streamjava.lang.Exception
- audio fault exception, e.g. can't open stream, unhandleable audio formatpublic static void play(java.net.URL url, double seconds) throws java.lang.Exception
url
- The resource to play, which must be a WAV file or streamseconds
- The number of seconds into the audio to start playingjava.lang.Exception
- 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.Exception
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.Exception
- audio fault exception, e.g. can't open stream, unhandleable audio formatpublic static void pause() throws java.lang.Exception
java.lang.Exception
- 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 static void audioMalfunction(java.lang.Exception ex)
ex
- The exception used as error reason. Cannot be null
.