public class Processor
extends java.lang.Object
implements java.lang.Runnable
Modifier and Type | Field and Description |
---|---|
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 and Description |
---|
Processor(java.lang.String name,
AudioFileLoader audioFileLoader)
Creates a new instance.
|
Modifier and Type | Method and Description |
---|---|
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.
|
@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
public Processor(@NotNull java.lang.String name, @NotNull AudioFileLoader audioFileLoader)
name
- the music name to playaudioFileLoader
- the audio file loader for loading audio filesprivate 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 openedjavax.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
).