AudioClip represents a segment of audio that can be played
with minimal latency. Clips are loaded similarly to Media
objects but have different behavior, for example, a Media cannot
play itself. AudioClips are also usable immediately. Playback
behavior is fire and forget: once one of the play methods is called the only
operable control is stop(). An AudioClip may also be
played multiple times simultaneously. To accomplish the same task using
Media one would have to create a new MediaPlayer
object for each sound played in parallel. Media objects are
however better suited for long-playing sounds. This is primarily because
AudioClip stores in memory the raw, uncompressed audio data for
the entire sound, which can be quite large for long audio clips. A
MediaPlayer will only have enough decompressed audio data
pre-rolled in memory to play for a short amount of time so it is much more
memory efficient for long clips, especially if they are compressed.
Example usage:
AudioClip plonkSound = new AudioClip("http://somehost/path/plonk.aiff");
plonkSound.play();
| Modifier and Type | Field and Description |
|---|---|
| private AudioClip | |
| private DoubleProperty | balance
The relative left and right volume levels of the clip. |
| private IntegerProperty | cycleCount
The number of times the clip will be played when |
| public static final int | INDEFINITE
When |
| private DoubleProperty | pan
The relative "center" of the clip. |
| private IntegerProperty | priority
The relative priority of the clip with respect to other clips. |
| private DoubleProperty | rate
The relative rate at which the clip is played. |
| private String | |
| private DoubleProperty | volume
The relative volume level at which the clip is played. |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public DoubleProperty | |
| public IntegerProperty | |
| public double | |
| public int | |
| public double | |
| public int | |
| public double | |
| public String | Returns: source URL as provided to the constructorGet the source URL used to create this |
| public final double | |
| public boolean | Returns: true if any mixer channel has this clip queued, false otherwiseIndicate whether this |
| public DoubleProperty | |
| public void | |
| public void | play(double
the volume level at which to play the clip volume)Play the |
| public void | play(double
Volume level at which to play this clip. Valid volume range is
0.0 to 1.0, where 0.0 is effectively muted and 1.0 is full volume. volume, double Left/right balance or relative channel volumes for stereo
effects. balance, double Playback rate multiplier. 1.0 will play at the normal
rate while 2.0 will double the rate. rate, double Left/right shift to be applied to the clip. A pan value of
-1.0 means full left channel, 1.0 means full right channel, 0.0 has no
effect. pan, int Audio effect priority. Lower priority effects will be
dropped first if too many effects are trying to play simultaneously. priority)Play the |
| public IntegerProperty | |
| public DoubleProperty | |
| public void | |
| public void | |
| public void | |
| public void | |
| public void | |
| public final void | |
| public void | |
| public DoubleProperty |
| audioClip | back to summary |
|---|---|
| private AudioClip audioClip | |
| balance | back to summary |
|---|---|
| private DoubleProperty balance The relative left and right volume levels of the clip. Valid range is -1.0 to 1.0 where -1.0 gives full volume to the left channel while muting the right channel, 0.0 gives full volume to both channels and 1.0 gives full volume to right channel and mutes the left channel. Values outside this range are clamped internally. | |
| cycleCount | back to summary |
|---|---|
| private IntegerProperty cycleCount The number of times the clip will be played when | |
| INDEFINITE | back to summary |
|---|---|
| public static final int INDEFINITE When | |
| pan | back to summary |
|---|---|
| private DoubleProperty pan The relative "center" of the clip. A pan value of 0.0 plays the clip normally where a -1.0 pan shifts the clip entirely to the left channel and 1.0 shifts entirely to the right channel. Unlike balance this setting mixes both channels so neither channel loses data. Setting pan on a mono clip has the same effect as setting balance, but with a much higher cost in CPU overhead so this is not recommended for mono clips. | |
| priority | back to summary |
|---|---|
| private IntegerProperty priority The relative priority of the clip with respect to other clips. This value is used to determine which clips to remove when the maximum allowed number of clips is exceeded. The lower the priority, the more likely the clip is to be stopped and removed from the mixer channel it is occupying. Valid range is any integer; there are no constraints. The default priority is zero for all clips until changed. The number of simultaneous sounds that can be played is implementation- and possibly system-dependent. | |
| rate | back to summary |
|---|---|
| private DoubleProperty rate The relative rate at which the clip is played. Valid range is 0.125 (1/8 speed) to 8.0 (8x speed); values outside this range are clamped internally. Normal playback for a clip is 1.0; any other rate will affect pitch and duration accordingly. | |
| sourceURL | back to summary |
|---|---|
| private String sourceURL | |
| volume | back to summary |
|---|---|
| private DoubleProperty volume The relative volume level at which the clip is played. Valid range is 0.0 (muted) to 1.0 (full volume). Values are clamped to this range internally so values outside this range will have no additional effect. Volume is controlled by attenuation, so values below 1.0 will reduce the sound level accordingly. | |
| AudioClip | back to summary |
|---|---|
| public AudioClip(String source) Create an
| |
| balanceProperty | back to summary |
|---|---|
| public DoubleProperty balanceProperty() | |
| cycleCountProperty | back to summary |
|---|---|
| public IntegerProperty cycleCountProperty() | |
| getBalance | back to summary |
|---|---|
| public double getBalance() Get the default balance level for this clip.
| |
| getCycleCount | back to summary |
|---|---|
| public int getCycleCount() Get the default cycle count.
| |
| getPan | back to summary |
|---|---|
| public double getPan() Get the default pan value.
| |
| getPriority | back to summary |
|---|---|
| public int getPriority() Get the default playback priority.
| |
| getRate | back to summary |
|---|---|
| public double getRate() Get the default playback rate.
| |
| getSource | back to summary |
|---|---|
| public String getSource() Get the source URL used to create this
| |
| getVolume | back to summary |
|---|---|
| public final double getVolume() Get the default volume level.
| |
| isPlaying | back to summary |
|---|---|
| public boolean isPlaying() Indicate whether this
| |
| panProperty | back to summary |
|---|---|
| public DoubleProperty panProperty() | |
| play | back to summary |
|---|---|
| public void play() Play the | |
| play | back to summary |
|---|---|
| public void play(double volume) Play the
| |
| play | back to summary |
|---|---|
| public void play(double volume, double balance, double rate, double pan, int priority) Play the
| |
| priorityProperty | back to summary |
|---|---|
| public IntegerProperty priorityProperty() | |
| rateProperty | back to summary |
|---|---|
| public DoubleProperty rateProperty() | |
| setBalance | back to summary |
|---|---|
| public void setBalance(double balance) Set the default balance level. The new value will only affect subsequent plays.
| |
| setCycleCount | back to summary |
|---|---|
| public void setCycleCount(int count) Set the default cycle count. The new value will only affect subsequent plays.
| |
| setPan | back to summary |
|---|---|
| public void setPan(double pan) Set the default pan value. The new value will only affect subsequent plays.
| |
| setPriority | back to summary |
|---|---|
| public void setPriority(int priority) Set the default playback priority. The new value will only affect subsequent plays.
| |
| setRate | back to summary |
|---|---|
| public void setRate(double rate) Set the default playback rate. The new value will only affect subsequent plays.
| |
| setVolume | back to summary |
|---|---|
| public final void setVolume(double value) Set the default volume level. The new setting will only take effect on subsequent plays.
| |
| stop | back to summary |
|---|---|
| public void stop() Immediately stop all playback of this | |
| volumeProperty | back to summary |
|---|---|
| public DoubleProperty volumeProperty() | |