ddf.minim
Class AudioPlayer

java.lang.Object
  extended by ddf.minim.Controller
      extended by ddf.minim.AudioSource
          extended by ddf.minim.AudioPlayer
All Implemented Interfaces:
Effectable, Playable, Recordable

public class AudioPlayer
extends AudioSource
implements Playable

An AudioPlayer is used for playing an AudioRecording. Strictly speaking, you don't need an AudioPlayer to play an AudioRecording, because the recording is itself Playable. However, an AudioPlayer does you the favor of providing AudioBuffers that are sync'd with the recording's output as well as providing direct control over the DataLine being used to transmit the recording to the system. You can get an AudioPlayer by calling Minim.loadFile(String), but you can also construct one yourself if you've written your own implementation of AudioRecording.

Author:
Damien Di Fede

Field Summary
 
Fields inherited from class ddf.minim.AudioSource
left, mix, right
 
Fields inherited from class ddf.minim.Controller
BALANCE, GAIN, MUTE, PAN, SAMPLE_RATE, VOLUME
 
Constructor Summary
AudioPlayer(AudioRecordingStream recording, AudioOut out)
          Constructs an AudioPlayer that plays recording.
 
Method Summary
 void close()
          Closes the AudioStream this was constructed with.
 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 this is currently playing and has more than one loop left to play.
 boolean isPlaying()
          Returns true if this currently playing.
 int length()
          Returns the length of the sound in milliseconds.
 void loop()
          Sets looping to continuous.
 void loop(int n)
          Sets this to loop num 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 millis from the beginning.
 int position()
          Returns the current position of the "playhead" (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 from the current position.
 
Methods inherited from class ddf.minim.AudioSource
addEffect, addListener, bufferSize, clearEffects, disableEffect, disableEffect, effectCount, effects, enableEffect, enableEffect, getEffect, getFormat, hasEffect, isEffected, isEnabled, noEffects, removeEffect, removeEffect, removeListener, sampleRate, type
 
Methods inherited from class ddf.minim.Controller
balance, gain, getBalance, getControl, getControls, getGain, getPan, getVolume, hasControl, isMuted, mute, pan, printControls, setBalance, setGain, setPan, setVolume, shiftBalance, shiftGain, shiftPan, shiftVolume, unmute, volume
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AudioPlayer

public AudioPlayer(AudioRecordingStream recording,
                   AudioOut out)
Constructs an AudioPlayer that plays recording. It is expected that recording will have a DataLine to control. If it doesn't, any calls to Controller's methods will result in a NullPointerException.

Parameters:
recording - the AudioRecording to play
Method Detail

play

public void play()
Description copied from interface: Playable
Starts playback from the current position. If this was previous set to loop, looping will be disabled.

Specified by:
play in interface Playable

play

public void play(int millis)
Description copied from interface: Playable
Starts playback millis from the beginning. If this was previous set to loop, looping will be disabled.

Specified by:
play in interface Playable

pause

public void pause()
Description copied from interface: Playable
Pauses playback.

Specified by:
pause in interface Playable

rewind

public void rewind()
Description copied from interface: Playable
Rewinds to the beginning. This does not stop playback.

Specified by:
rewind in interface Playable

loop

public void loop()
Description copied from interface: Playable
Sets looping to continuous. If this is already playing, the position will not be reset to the beginning. If this is not playing, it will start playing.

Specified by:
loop in interface Playable

loop

public void loop(int n)
Description copied from interface: Playable
Sets this to loop num times. If this is already playing, the position will not be reset to the beginning. If this is not playing, it will start playing.

Specified by:
loop in interface Playable
Parameters:
n - the number of times to loop

loopCount

public int loopCount()
Description copied from interface: Playable
Returns the number of loops left to do.

Specified by:
loopCount in interface Playable
Returns:
the number of loops left

length

public int length()
Description copied from interface: Playable
Returns the length of the sound in milliseconds. If for any reason the length could not be determined, this will return -1. However, an unknown length should not impact playback.

Specified by:
length in interface Playable
Returns:
the length of the sound in milliseconds

position

public int position()
Description copied from interface: Playable
Returns the current position of the "playhead" (ie how much of the sound has already been played)

Specified by:
position in interface Playable
Returns:
the current position of the "playhead"

cue

public void cue(int millis)
Description copied from interface: Playable
Sets the position to millis milliseconds from the beginning. This will not change the playstate. If an error occurs while trying to cue, the position will not change. If you try to cue to a negative position or try to a position that is greater than length(), the amount will be clamped to zero or length().

Specified by:
cue in interface Playable
Parameters:
millis - the position to place the "playhead"

skip

public void skip(int millis)
Description copied from interface: Playable
Skips millis 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().

Specified by:
skip in interface Playable
Parameters:
millis - how many milliseconds to skip, sign indicates direction

isLooping

public boolean isLooping()
Description copied from interface: Playable
Returns true if this is currently playing and has more than one loop left to play.

Specified by:
isLooping in interface Playable
Returns:
true if this is looping

isPlaying

public boolean isPlaying()
Description copied from interface: Playable
Returns true if this currently playing.

Specified by:
isPlaying in interface Playable
Returns:
true if this is currently playing

getMetaData

public AudioMetaData getMetaData()
Returns the meta data for the recording being played by this player.

Specified by:
getMetaData in interface Playable
Returns:
the meta data for this player's recording

setLoopPoints

public void setLoopPoints(int start,
                          int stop)
Description copied from interface: Playable
Sets the loop points used when looping.

Specified by:
setLoopPoints in interface Playable
Parameters:
start - the start of the loop in milliseconds
stop - the end of the loop in milliseconds

close

public void close()
Description copied from class: AudioSource
Closes the AudioStream this was constructed with.

Overrides:
close in class AudioSource