Package org.openstreetmap.josm.io.audio
Class AudioPlayer
- java.lang.Object
-
- java.lang.Thread
-
- org.openstreetmap.josm.io.audio.AudioPlayer
-
- All Implemented Interfaces:
Runnable
,AudioListener
public final class AudioPlayer extends Thread implements AudioListener
Creates and controls a separate audio player thread.- Since:
- 12326 (move to new package), 547
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
AudioPlayer.Command
Audio player command.class
AudioPlayer.Execute
Passes information from the control thread to the playing threadstatic class
AudioPlayer.Result
Audio player result.static class
AudioPlayer.State
Audio player state.-
Nested classes/interfaces inherited from class java.lang.Thread
Thread.UncaughtExceptionHandler
-
-
Field Summary
Fields Modifier and Type Field Description private static AudioPlayer
audioPlayer
private AudioPlayer.Execute
command
private URL
playingUrl
private SoundPlayer
soundPlayer
private static Class<? extends SoundPlayer>
soundPlayerClass
private AudioPlayer.State
state
-
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
-
-
Constructor Summary
Constructors Modifier Constructor Description private
AudioPlayer()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static AudioPlayer
getInstance()
Returns the singleton object, and if this is the first time, creates it along with the thread to support audiostatic Class<? extends SoundPlayer>
getSoundPlayerClass()
Returns the custom sound player class, if any.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.void
playing(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 privatestatic void
setSoundPlayerClass(Class<? extends SoundPlayer> playerClass)
Sets the custom sound player class to override default core player.static double
speed()
Speed at which we will play.static URL
url()
To get the Url of the playing or recently played audio.-
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
-
-
-
-
Field Detail
-
audioPlayer
private static volatile AudioPlayer audioPlayer
-
state
private AudioPlayer.State state
-
soundPlayerClass
private static volatile Class<? extends SoundPlayer> soundPlayerClass
-
soundPlayer
private SoundPlayer soundPlayer
-
playingUrl
private URL playingUrl
-
command
private final AudioPlayer.Execute command
-
-
Constructor Detail
-
AudioPlayer
private AudioPlayer()
-
-
Method Detail
-
play
public static void play(URL url) throws InterruptedException, IOException
Plays a WAV audio file from the beginning. See also the variant which doesn't start at the beginning of the stream- Parameters:
url
- The resource to play, which must be a WAV file or stream- Throws:
InterruptedException
- thread interruptedIOException
- audio fault exception, e.g. can't open stream, unhandleable audio format
-
play
public static void play(URL url, double seconds) throws InterruptedException, IOException
Plays a WAV audio file from a specified position.- Parameters:
url
- The resource to play, which must be a WAV file or streamseconds
- The number of seconds into the audio to start playing- Throws:
InterruptedException
- thread interruptedIOException
- audio fault exception, e.g. can't open stream, unhandleable audio format
-
play
public static void play(URL url, double seconds, double speed) throws InterruptedException, IOException
Plays a WAV audio file from a specified position at variable speed.- Parameters:
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 plays (1.0 = real time, > 1 is faster)- Throws:
InterruptedException
- thread interruptedIOException
- audio fault exception, e.g. can't open stream, unhandleable audio format
-
pause
public static void pause() throws InterruptedException, IOException
Pauses the currently playing audio stream. Does nothing if nothing playing.- Throws:
InterruptedException
- thread interruptedIOException
- audio fault exception, e.g. can't open stream, unhandleable audio format
-
url
public static URL url()
To get the Url of the playing or recently played audio.- Returns:
- url - could be null
-
paused
public static boolean paused()
Whether or not we are paused.- Returns:
- boolean whether or not paused
-
playing
public static boolean playing()
Whether or not we are playing.- Returns:
- boolean whether or not playing
-
position
public static double position()
How far we are through playing, in seconds.- Returns:
- double seconds
-
speed
public static double speed()
Speed at which we will play.- Returns:
- double, speed multiplier
-
getInstance
private static AudioPlayer getInstance()
Returns the singleton object, and if this is the first time, creates it along with the thread to support audio- Returns:
- the unique instance
-
reset
public static void reset()
Resets the audio player.
-
run
public 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
-
playing
public void playing(URL playingUrl)
Description copied from interface:AudioListener
Called when a new URL is being played.- Specified by:
playing
in interfaceAudioListener
- Parameters:
playingUrl
- new URL being played
-
getSoundPlayerClass
public static Class<? extends SoundPlayer> getSoundPlayerClass()
Returns the custom sound player class, if any.- Returns:
- the custom sound player class, or
null
- Since:
- 14183
-
setSoundPlayerClass
public static void setSoundPlayerClass(Class<? extends SoundPlayer> playerClass)
Sets the custom sound player class to override default core player. Must be called before the first audio method invocation.- Parameters:
playerClass
- custom sound player class to override default core player- Since:
- 14183
-
-