|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object | +--mediaframe.mpeg1.audio.player.JavaSoundAudioDevice
The JavaSoundAudioDevice class implements an audio
device by using the JavaSound API.
| Field Summary | |
private static int |
bufferMs
Constanta, equals to four seconds in milliseconds. |
private byte[] |
byteBuf
The temporary buffer for storing the audio data. |
private mediaframe.mpeg1.audio.decoder.Decoder |
decoder
The decoder that provides audio data to this audio device. |
private javax.sound.sampled.AudioFormat |
fmt
The Audio Format for the MPEG audio stream. |
private float |
masterGain
The master gain volume value of the Java Sound audio device. |
private float |
oldSampleRate
The sample rate (speed) of the current audio playback (0 - the playback is paused, > 0 otherwise). |
private boolean |
open
True if this audio device is opened. |
private boolean |
playing
True if the audio player is playing the sound, false if the playback is paused. |
private javax.sound.sampled.SourceDataLine |
source
The source audio line that plays the audio stream. |
private boolean |
stopped
True if this audio device is stoped. |
| Constructor Summary | |
JavaSoundAudioDevice()
|
|
| Method Summary | |
void |
close()
Closes this audio device. |
protected void |
createSource()
Obtains and opens the source audio line using the Audio Format of the MPEG audio stream. |
void |
endOfFile()
Is called if the end of file has been reached. |
void |
flush()
Waits for any buffered audio samples to be played by the audio device. |
protected javax.sound.sampled.AudioFormat |
getAudioFormat()
Gets the Audio Format for the MPEG audio stream. |
protected byte[] |
getByteArray(int length)
Gets the buffer that able to store up to length bytes. |
boolean |
isEightBitEightKhzMuLaw()
Returns false because the JavaSoundAudioDevice audio device is not a
crappy eight-bit eight khz ulaw decoder (browser). |
protected int |
millisecondsToBytes(javax.sound.sampled.AudioFormat _fmt,
int time)
Calculates the number of bytes required for storing the audio samples for the specified time and the audio format. |
void |
open(mediaframe.mpeg1.audio.decoder.Decoder decoder)
Opens this audio device. |
void |
pause()
Stop player playing. |
void |
play()
Start player playing. |
void |
setMute(boolean mute)
Sets the mute state of the audio playback. |
void |
setVolume(float volume)
Sets the volume (in the range 0..1) of the audio playback. |
void |
stop()
Stop player playing. |
protected byte[] |
toByteArray(short[] samples,
int offs,
int len)
Returns the byte array with up to len audio samples (two bytes each)
from the samples |
void |
write(short[] samples,
int offs,
int len)
Writes audio data to this audio device. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
private javax.sound.sampled.SourceDataLine source
private javax.sound.sampled.AudioFormat fmt
private byte[] byteBuf
private boolean playing
private float oldSampleRate
private static final int bufferMs
private boolean open
private boolean stopped
private mediaframe.mpeg1.audio.decoder.Decoder decoder
private float masterGain
| Constructor Detail |
public JavaSoundAudioDevice()
| Method Detail |
public void open(mediaframe.mpeg1.audio.decoder.Decoder decoder)
open in interface AudioDevicedecoder - the decoder that will provide audio data
to this audio device.public boolean isEightBitEightKhzMuLaw()
JavaSoundAudioDevice audio device is not a
crappy eight-bit eight khz ulaw decoder (browser).
isEightBitEightKhzMuLaw in interface AudioDeviceprotected javax.sound.sampled.AudioFormat getAudioFormat()
protected void createSource()
throws mediaframe.mpeg1.audio.decoder.JavaLayerException
mediaframe.mpeg1.audio.decoder.JavaLayerException - if the source data line could not be obtained and opened.
protected int millisecondsToBytes(javax.sound.sampled.AudioFormat _fmt,
int time)
_fmt - the format of the audio stream.time - the time in milliseconds that should be buffered.
public void close()
close in interface AudioDevice
public void write(short[] samples,
int offs,
int len)
throws mediaframe.mpeg1.audio.decoder.JavaLayerException
write in interface AudioDevicesamples - the samples to write to the audio device.offs - the offset into the array of the first sample to write.len - the number of samples from the array to write.
mediaframe.mpeg1.audio.decoder.JavaLayerException - if the audio data could not be
written to the audio device.protected byte[] getByteArray(int length)
length bytes.
length - min size of the temporary buffer.
protected byte[] toByteArray(short[] samples,
int offs,
int len)
len audio samples (two bytes each)
from the samples array starting at offset offset.
- Parameters:
samples - the audio data.offs - the start offset in the data.len - the number of samples to copy.
- Returns:
- the byte array with the audio data.
public void flush()
flush in interface AudioDevicepublic void play()
play in interface AudioDevicepublic void setVolume(float volume)
setVolume in interface AudioDevicevolume - the volume to set.public void setMute(boolean mute)
setMute in interface AudioDevicemute - the mute state (true if the mute on and the player doesn't play the audio).public void stop()
stop in interface AudioDevicepublic void pause()
pause in interface AudioDevicepublic void endOfFile()
endOfFile in interface AudioDevice
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||