public class RawFileAudioPlayer extends Object implements AudioPlayer
AudioPlayer
that sends
all audio data to the given file.Modifier and Type | Field and Description |
---|---|
private AudioFormat |
audioFormat |
private BufferedOutputStream |
os |
private String |
path |
private float |
volume |
Constructor and Description |
---|
RawFileAudioPlayer()
Creates a default audio player for an AudioFileFormat of type
WAVE.
|
RawFileAudioPlayer(String path)
Constructs a NullAudioPlayer
|
Modifier and Type | Method and Description |
---|---|
void |
begin(int size)
Starts the output of a set of data
|
void |
cancel()
Cancels all queued output.
|
void |
close()
Waits for all audio playback to stop, and closes this AudioPlayer.
|
boolean |
drain()
Waits for all queued audio to be played
|
boolean |
end()
Marks the end of a set of data
|
AudioFormat |
getAudioFormat()
Retrieves the audio format for this player
|
long |
getTime()
Gets the amount of played since the last resetTime
Currently not supported.
|
float |
getVolume()
Returns the current volume.
|
void |
pause()
Pauses the audio output
|
void |
reset()
Prepares for another batch of output.
|
void |
resetTime()
Resets the audio clock
|
void |
resume()
Resumes audio output
|
void |
setAudioFormat(AudioFormat format)
Sets the audio format for this player
|
void |
setVolume(float volume)
Sets the current volume.
|
void |
showMetrics()
Shows metrics for this audio player
|
void |
startFirstSampleTimer()
Starts the first sample timer
|
boolean |
write(byte[] audioData)
Writes the given bytes to the audio stream
|
boolean |
write(byte[] bytes,
int offset,
int size)
Writes the given bytes to the audio stream
|
private AudioFormat audioFormat
private float volume
private BufferedOutputStream os
public RawFileAudioPlayer() throws IOException
IOException
public RawFileAudioPlayer(String path) throws IOException
IOException
public void setAudioFormat(AudioFormat format)
setAudioFormat
in interface AudioPlayer
format
- the audio formatpublic AudioFormat getAudioFormat()
getAudioFormat
in interface AudioPlayer
public void cancel()
cancel
in interface AudioPlayer
public void pause()
pause
in interface AudioPlayer
public void reset()
reset
in interface AudioPlayer
public void resume()
resume
in interface AudioPlayer
public void close() throws IOException
close
in interface AudioPlayer
IOException
- error closing the audio playerpublic float getVolume()
getVolume
in interface AudioPlayer
public void setVolume(float volume)
setVolume
in interface AudioPlayer
volume
- the current volume (between 0 and 1)public boolean write(byte[] audioData) throws IOException
write
in interface AudioPlayer
audioData
- audio data to write to the devicetrue
of the write completed successfully,
false
if the write was cancelled.IOException
- if an error occurs while writing the audio datapublic void begin(int size)
begin
in interface AudioPlayer
size
- the size of data between now and the endpublic boolean end()
end
in interface AudioPlayer
true
if the audio was output properly,
false
if the output was canceled
or interrupted.public boolean write(byte[] bytes, int offset, int size) throws IOException
write
in interface AudioPlayer
bytes
- audio data to write to the deviceoffset
- the offset into the buffersize
- the number of bytes to write.true
of the write completed successfully,
false
if the write was cancelled.IOException
- if an error occurs while writing the audio datapublic void startFirstSampleTimer()
startFirstSampleTimer
in interface AudioPlayer
public boolean drain()
drain
in interface AudioPlayer
true
if the audio played to completion,
false
if the audio was stoppedpublic long getTime()
getTime
in interface AudioPlayer
public void resetTime()
resetTime
in interface AudioPlayer
public void showMetrics()
showMetrics
in interface AudioPlayer
WebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses