java.lang.Object com.realtime.crossfire.jxclient.sound.Processor
public class Processor
A thread that plays a music file over and over until terminated.
Field Summary | |
---|---|
private AudioFileLoader |
audioFileLoader
The AudioFileLoader for loading audio files. |
private static float |
MIN_VALUE
The minimum factor for fading in/out effects. |
private java.lang.String |
name
The name of the music to play. |
private int |
state
The current state: 0=fade in, 1=playing, 2=fade out, 3=terminate, 4=terminate immediately. |
private float |
volume
The current volume. |
private static float |
VOLUME_STEP_PER_SAMPLE
The step for the fading in/out factor. |
Constructor Summary | |
---|---|
Processor(java.lang.String name,
AudioFileLoader audioFileLoader)
Creates a new instance. |
Method Summary | |
---|---|
private void |
convertSample(byte[] buf,
int i)
Converts one audio sample according to the current volume . |
private javax.sound.sampled.AudioInputStream |
openAudioInputStream()
Opens and returns an audio stream for name . |
void |
run()
|
void |
terminate(boolean fadeOut)
Stops playing music. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
@NotNull private final AudioFileLoader audioFileLoader
AudioFileLoader
for loading audio files.
private static final float MIN_VALUE
@NotNull private final java.lang.String name
private int state
private float volume
private static final float VOLUME_STEP_PER_SAMPLE
Constructor Detail |
---|
public Processor(@NotNull java.lang.String name, @NotNull AudioFileLoader audioFileLoader)
name
- the music name to playaudioFileLoader
- the audio file loader for loading audio filesMethod Detail |
---|
private void convertSample(@NotNull byte[] buf, int i)
volume
.
buf
- the buffer holding the samplei
- the sample offset@NotNull private javax.sound.sampled.AudioInputStream openAudioInputStream() throws java.io.IOException, javax.sound.sampled.UnsupportedAudioFileException
name
.
java.io.IOException
- if the file cannot be opened
javax.sound.sampled.UnsupportedAudioFileException
- if the file cannot be decodedpublic void run()
run
in interface java.lang.Runnable
public void terminate(boolean fadeOut)
fadeOut
- Whether tp fade out the music (true
) or to
cut it off (false
).