public class AudioPlayer extends Object implements Runnable, TimeKeeper<AudioTimecode>
The AudioPlayer supports the TimeKeeper interface so that
other methods can synchronise to the audio timestamps.
The Audio Player as a TimeKeeper supports seeking but it may be
possible that the underlying stream does not support seeking so the seek
method may not affect the time keeper as expected.
| Modifier and Type | Class and Description |
|---|---|
static class |
AudioPlayer.Mode
Enumerator for the current state of the audio player.
|
| Constructor and Description |
|---|
AudioPlayer(AudioStream a)
Default constructor that takes an audio stream to play.
|
AudioPlayer(AudioStream a,
String deviceName)
Play the given stream to a specific device.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addAudioEventListener(AudioEventListener l)
Add the given audio event listener to this player.
|
static AudioPlayer |
createAudioPlayer(AudioStream as)
Create a new audio player in a separate thread for playing audio.
|
static AudioPlayer |
createAudioPlayer(AudioStream as,
String device)
Create a new audio player in a separate thread for playing audio.
|
protected void |
fireAfterPlay(SampleChunk sc)
Fires an event that says the samples have been played.
|
protected void |
fireAudioEnded(AudioStream as)
Fires the audio ended event to the listeners.
|
protected void |
fireBeforePlay(SampleChunk sc)
Fires an event that says the samples will be played.
|
AudioTimecode |
getTime()
Returns the current time.
|
Timecode |
getTimecodeObject()
Returns the current timecode.
|
void |
pause()
Pause the running of the timekeeper.
|
void |
removeAudioEventListener(AudioEventListener l)
Remove the given event from the listeners on this player.
|
void |
reset()
Reset the timekeeper.
|
void |
run()
Use this method to start the time keeper running.
|
void |
seek(long timestamp)
Seek to a given timestamp.
|
void |
setMode(AudioPlayer.Mode m)
Set the mode of the player.
|
void |
setSoundLineBufferSize(double ms)
Set the length of the sound line's buffer in milliseconds.
|
void |
setTimecodeObject(AudioTimecode t)
Set the timecode object that is updated as the audio is played.
|
void |
stop()
Use this method to stop the time keeper from running.
|
boolean |
supportsPause()
Returns whether the timekeeper supports pausing.
|
boolean |
supportsSeek()
Returns whether the timekeeper supports seeking.
|
public AudioPlayer(AudioStream a)
a - The audio stream to playpublic AudioPlayer(AudioStream a, String deviceName)
a - The audio stream to play.deviceName - The device to play the audio to.public void setSoundLineBufferSize(double ms)
ms - The length of the sound line in milliseconds.public void addAudioEventListener(AudioEventListener l)
l - The listener to add.public void removeAudioEventListener(AudioEventListener l)
l - The listener to remove.protected void fireAudioEnded(AudioStream as)
as - The audio stream that endedprotected void fireBeforePlay(SampleChunk sc)
sc - The samples to playprotected void fireAfterPlay(SampleChunk sc)
sc - The sampled have been playedpublic void setTimecodeObject(AudioTimecode t)
t - The timecode object.public Timecode getTimecodeObject()
public void run()
run in interface Runnablerun in interface TimeKeeper<AudioTimecode>Runnable.run()public static AudioPlayer createAudioPlayer(AudioStream as)
as - The audio stream to play.public static AudioPlayer createAudioPlayer(AudioStream as, String device)
AudioUtils.getDevices().as - The audio stream to play.device - The name of the device to use.public AudioTimecode getTime()
getTime in interface TimeKeeper<AudioTimecode>TimeKeeper.getTime()public void stop()
stop in interface TimeKeeper<AudioTimecode>TimeKeeper.stop()public void setMode(AudioPlayer.Mode m)
m - public boolean supportsPause()
supportsPause in interface TimeKeeper<AudioTimecode>TimeKeeper.supportsPause()public boolean supportsSeek()
supportsSeek in interface TimeKeeper<AudioTimecode>TimeKeeper.supportsSeek()public void seek(long timestamp)
seek in interface TimeKeeper<AudioTimecode>timestamp - The timestamp to seek toTimeKeeper.seek(long)public void reset()
reset in interface TimeKeeper<AudioTimecode>TimeKeeper.reset()public void pause()
pause in interface TimeKeeper<AudioTimecode>TimeKeeper.pause()