public class AudioPlayer extends AudioSource implements Playable
AudioPlayer
provides a self-contained way of playing a
sound file by streaming it from disk (or the internet). It
provides methods for playing and looping the file, as well
as methods for setting the position in the file and
looping a section of the file. You can obtain an
AudioPlayer
by using the loadFile method of the Minim
class.left, mix, right
BALANCE, GAIN, MUTE, PAN, SAMPLE_RATE, VOLUME
Constructor and Description |
---|
AudioPlayer(ddf.minim.spi.AudioRecordingStream recording,
ddf.minim.spi.AudioOut out)
Constructs an
AudioPlayer that plays recording using
the AudioOut provided. |
Modifier and Type | Method and Description |
---|---|
void |
close()
Release the resources associated with playing this file.
|
void |
cue(int millis)
Sets the position to
millis milliseconds from
the beginning. |
AudioMetaData |
getMetaData()
Returns the meta data for the recording being played by this player.
|
boolean |
isLooping()
Returns true if the
AudioPlayer is currently playing
and has more than one loop left to play. |
boolean |
isPlaying()
Indicates if the
AudioPlayer is currently playing. |
int |
length()
Returns the length of the sound in milliseconds.
|
void |
loop()
Sets the
AudioPlayer to loop indefinitely. |
void |
loop(int num)
Set the
AudioPlayer to loop some number of times. |
int |
loopCount()
Returns the number of loops left to do.
|
void |
pause()
Pauses playback.
|
void |
play()
Starts playback from the current position.
|
void |
play(int millis)
Starts playback some number of milliseconds into the file.
|
int |
position()
Returns the current position of the "playhead" in milliseconds
(ie how much of the sound has already been played).
|
void |
rewind()
Rewinds to the beginning.
|
void |
setLoopPoints(int start,
int stop)
Sets the loop points used when looping.
|
void |
skip(int millis)
Skips
millis milliseconds from the current position. |
addEffect, addListener, bufferSize, clearEffects, disableEffect, disableEffect, effectCount, effects, enableEffect, enableEffect, getEffect, getFormat, hasEffect, isEffected, isEnabled, noEffects, removeEffect, removeEffect, removeListener, sampleRate, type
balance, gain, getBalance, getControl, getControls, getGain, getPan, getVolume, hasControl, isMuted, mute, pan, printControls, setBalance, setGain, setPan, setVolume, shiftBalance, shiftGain, shiftPan, shiftVolume, unmute, volume
public AudioPlayer(ddf.minim.spi.AudioRecordingStream recording, ddf.minim.spi.AudioOut out)
AudioPlayer
that plays recording
using
the AudioOut
provided. Generally you will not call this directly
and will instead use the Minim.loadFile
method.recording
- the AudioRecordingStream
to playout
- the AudioOut
to play the recording onMinim.loadFile(String)
public void play()
public void play(int millis)
public void rewind()
public void loop(int num)
AudioPlayer
to loop some number of times.
If it is already playing, the position
will not be reset to the beginning.
If it is not playing, it will start playing.
If you previously called this method and then paused the
AudioPlayer
, you can resume looping
by using the result of getLoopCount()
as
the argument for this method.
To loop indefinitely, use loop()
.public void loop()
AudioPlayer
to loop indefinitely.
If it is already playing, the position
will not be reset to the beginning.
If it is not playing, it will start playing.public int loopCount()
public int length()
public int position()
public void cue(int millis)
millis
milliseconds from
the beginning. This will not change the play state. If an error
occurs while trying to cue, the position will not change.
If you try to cue to a negative position or to a position
that is greater than length()
, the amount will be clamped
to zero or length()
.public void skip(int millis)
millis
milliseconds from the current position.
millis
can be negative, which will make this skip backwards.
If the skip amount would result in a negative position or a position that is greater than
length()
, the new position will be clamped to zero or
length()
.public boolean isLooping()
AudioPlayer
is currently playing
and has more than one loop left to play.public boolean isPlaying()
AudioPlayer
is currently playing.public AudioMetaData getMetaData()
getMetaData
in interface Playable
AudioMetaData
public void setLoopPoints(int start, int stop)
setLoopPoints
in interface Playable
start
- int: the start of the loop in millisecondsstop
- int: the end of the loop in millisecondspublic void close()
close
in class AudioSource