Package org.openstreetmap.josm.io.audio
Class JavaSoundPlayer
- java.lang.Object
-
- org.openstreetmap.josm.io.audio.JavaSoundPlayer
-
- All Implemented Interfaces:
SoundPlayer
class JavaSoundPlayer extends java.lang.Object implements SoundPlayer
Legacy sound player based on the Java Sound API. Used on platforms where Java FX is not yet available. It supports only WAV files.- Since:
- 12328
-
-
Field Summary
Fields Modifier and Type Field Description private byte[]abDataprivate javax.sound.sampled.AudioInputStreamaudioInputStreamprivate javax.sound.sampled.SourceDataLineaudioOutputLineprivate doublebytesPerSecondprivate doublecalibrationprivate static intchunkprivate doubleleadInprivate ListenerList<AudioListener>listenersprivate doublepositionprivate doublespeed
-
Constructor Summary
Constructors Constructor Description JavaSoundPlayer(double leadIn, double calibration)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddAudioListener(AudioListener listener)Adds a listener that will be notified of audio playback events.voidpause(AudioPlayer.Execute command, AudioPlayer.State stateChange, java.net.URL playingUrl)Ask player to pause the current playing media.voidplay(AudioPlayer.Execute command, AudioPlayer.State stateChange, java.net.URL playingUrl)Ask player to play a new media.booleanplaying(AudioPlayer.Execute command)Method called when a media is being played.doubleposition()Returns the media playback position, in seconds.doublespeed()Returns the media playback speed ratio.
-
-
-
Field Detail
-
chunk
private static final int chunk
- See Also:
- Constant Field Values
-
audioInputStream
private javax.sound.sampled.AudioInputStream audioInputStream
-
audioOutputLine
private javax.sound.sampled.SourceDataLine audioOutputLine
-
leadIn
private final double leadIn
-
calibration
private final double calibration
-
bytesPerSecond
private double bytesPerSecond
-
abData
private final byte[] abData
-
position
private double position
-
speed
private double speed
-
listeners
private final ListenerList<AudioListener> listeners
-
-
Constructor Detail
-
JavaSoundPlayer
JavaSoundPlayer(double leadIn, double calibration)
-
-
Method Detail
-
play
public void play(AudioPlayer.Execute command, AudioPlayer.State stateChange, java.net.URL playingUrl) throws AudioException, java.io.IOException
Description copied from interface:SoundPlayerAsk player to play a new media.- Specified by:
playin interfaceSoundPlayer- Parameters:
command- Command containing media informationstateChange- the previous stateplayingUrl- the currently playing URL, if any- Throws:
AudioException- if an audio error occursjava.io.IOException- if an I/O error occurs
-
pause
public void pause(AudioPlayer.Execute command, AudioPlayer.State stateChange, java.net.URL playingUrl) throws AudioException, java.io.IOException
Description copied from interface:SoundPlayerAsk player to pause the current playing media.- Specified by:
pausein interfaceSoundPlayer- Parameters:
command- Command containing media informationstateChange- the previous stateplayingUrl- the currently playing URL, if any- Throws:
AudioException- if an audio error occursjava.io.IOException- if an I/O error occurs
-
playing
public boolean playing(AudioPlayer.Execute command) throws AudioException, java.io.IOException, java.lang.InterruptedException
Description copied from interface:SoundPlayerMethod called when a media is being played.- Specified by:
playingin interfaceSoundPlayer- Parameters:
command- Command containing media information- Returns:
trueif the playing call was blocking, and the playback is finished when this method returns- Throws:
AudioException- if an audio error occursjava.io.IOException- if an I/O error occursjava.lang.InterruptedException- if the play is interrupted
-
position
public double position()
Description copied from interface:SoundPlayerReturns the media playback position, in seconds.- Specified by:
positionin interfaceSoundPlayer- Returns:
- the media playback position, in seconds
-
speed
public double speed()
Description copied from interface:SoundPlayerReturns the media playback speed ratio.- Specified by:
speedin interfaceSoundPlayer- Returns:
- the media playback speed ratio
-
addAudioListener
public void addAudioListener(AudioListener listener)
Description copied from interface:SoundPlayerAdds a listener that will be notified of audio playback events.- Specified by:
addAudioListenerin interfaceSoundPlayer- Parameters:
listener- audio listener
-
-