Package org.openstreetmap.josm.io.audio
Class AudioPlayer
- java.lang.Object
-
- java.lang.Thread
-
- org.openstreetmap.josm.io.audio.AudioPlayer
-
- All Implemented Interfaces:
java.lang.Runnable,AudioListener
public final class AudioPlayer extends java.lang.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 classAudioPlayer.CommandAudio player command.classAudioPlayer.ExecutePasses information from the control thread to the playing threadstatic classAudioPlayer.ResultAudio player result.static classAudioPlayer.StateAudio player state.
-
Field Summary
Fields Modifier and Type Field Description private static AudioPlayeraudioPlayerprivate AudioPlayer.Executecommandprivate java.net.URLplayingUrlprivate SoundPlayersoundPlayerprivate static java.lang.Class<? extends SoundPlayer>soundPlayerClassprivate AudioPlayer.Statestate
-
Constructor Summary
Constructors Modifier Constructor Description privateAudioPlayer()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static AudioPlayergetInstance()Returns the singleton object, and if this is the first time, creates it along with the thread to support audiostatic java.lang.Class<? extends SoundPlayer>getSoundPlayerClass()Returns the custom sound player class, if any.static voidpause()Pauses the currently playing audio stream.static booleanpaused()Whether or not we are paused.static voidplay(java.net.URL url)Plays a WAV audio file from the beginning.static voidplay(java.net.URL url, double seconds)Plays a WAV audio file from a specified position.static voidplay(java.net.URL url, double seconds, double speed)Plays a WAV audio file from a specified position at variable speed.static booleanplaying()Whether or not we are playing.voidplaying(java.net.URL playingUrl)Called when a new URL is being played.static doubleposition()How far we are through playing, in seconds.static voidreset()Resets the audio player.voidrun()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 voidsetSoundPlayerClass(java.lang.Class<? extends SoundPlayer> playerClass)Sets the custom sound player class to override default core player.static doublespeed()Speed at which we will play.static java.net.URLurl()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 java.lang.Class<? extends SoundPlayer> soundPlayerClass
-
soundPlayer
private SoundPlayer soundPlayer
-
playingUrl
private java.net.URL playingUrl
-
command
private final AudioPlayer.Execute command
-
-
Constructor Detail
-
AudioPlayer
private AudioPlayer()
-
-
Method Detail
-
play
public static void play(java.net.URL url) throws java.lang.InterruptedException, java.io.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:
java.lang.InterruptedException- thread interruptedjava.io.IOException- audio fault exception, e.g. can't open stream, unhandleable audio format
-
play
public static void play(java.net.URL url, double seconds) throws java.lang.InterruptedException, java.io.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:
java.lang.InterruptedException- thread interruptedjava.io.IOException- audio fault exception, e.g. can't open stream, unhandleable audio format
-
play
public static void play(java.net.URL url, double seconds, double speed) throws java.lang.InterruptedException, java.io.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:
java.lang.InterruptedException- thread interruptedjava.io.IOException- audio fault exception, e.g. can't open stream, unhandleable audio format
-
pause
public static void pause() throws java.lang.InterruptedException, java.io.IOException
Pauses the currently playing audio stream. Does nothing if nothing playing.- Throws:
java.lang.InterruptedException- thread interruptedjava.io.IOException- audio fault exception, e.g. can't open stream, unhandleable audio format
-
url
public static java.net.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- Specified by:
runin interfacejava.lang.Runnable- Overrides:
runin classjava.lang.Thread
-
playing
public void playing(java.net.URL playingUrl)
Description copied from interface:AudioListenerCalled when a new URL is being played.- Specified by:
playingin interfaceAudioListener- Parameters:
playingUrl- new URL being played
-
getSoundPlayerClass
public static java.lang.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(java.lang.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
-
-