public final class AudioPlayer extends 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 |
Thread.UncaughtExceptionHandler
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 URL |
playingUrl |
private double |
position |
private double |
speed |
private AudioPlayer.State |
state |
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
Modifier | Constructor and Description |
---|---|
private |
AudioPlayer() |
Modifier and Type | Method and Description |
---|---|
static void |
audioMalfunction(Exception ex)
Shows a popup audio error message for the given exception.
|
private static AudioPlayer |
get()
gets 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(URL url)
Plays a WAV audio file from the beginning.
|
static void |
play(URL url,
double seconds)
Plays a WAV audio file from a specified position.
|
static void |
play(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 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 AudioPlayer audioPlayer
private AudioPlayer.State state
private 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(URL url) throws Exception
url
- The resource to play, which must be a WAV file or streamException
- audio fault exception, e.g. can't open stream, unhandleable audio formatpublic static void play(URL url, double seconds) throws Exception
url
- The resource to play, which must be a WAV file or streamseconds
- The number of seconds into the audio to start playingException
- audio fault exception, e.g. can't open stream, unhandleable audio formatpublic static void play(URL url, double seconds, double speed) throws 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)Exception
- audio fault exception, e.g. can't open stream, unhandleable audio formatpublic static void pause() throws Exception
Exception
- audio fault exception, e.g. can't open stream, unhandleable audio formatpublic static URL url()
public static boolean paused()
public static boolean playing()
public static double position()
public static double speed()
private static AudioPlayer get()
public static void reset()
public void run()
public static void audioMalfunction(Exception ex)
ex
- The exception used as error reason. Cannot be null
.