public final class AudioClip extends Object
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();
| Type | Property and Description |
|---|---|
DoubleProperty |
balance
The relative left and right volume levels of the clip.
|
IntegerProperty |
cycleCount
The number of times the clip will be played when
play()
is called. |
DoubleProperty |
pan
The relative "center" of the clip.
|
IntegerProperty |
priority
The relative priority of the clip with respect to other clips.
|
DoubleProperty |
rate
The relative rate at which the clip is played.
|
DoubleProperty |
volume
The relative volume level at which the clip is played.
|
| Modifier and Type | Field and Description |
|---|---|
static int |
INDEFINITE
When
cycleCount is set to this value, the
AudioClip will loop continuously until stopped. |
| Constructor and Description |
|---|
AudioClip(String source)
Create an
AudioClip loaded from the supplied source URL. |
| Modifier and Type | Method and Description |
|---|---|
DoubleProperty |
balanceProperty()
The relative left and right volume levels of the clip.
|
IntegerProperty |
cycleCountProperty()
The number of times the clip will be played when
play()
is called. |
double |
getBalance()
Get the default balance level for this clip.
|
int |
getCycleCount()
Get the default cycle count.
|
double |
getPan()
Get the default pan value.
|
int |
getPriority()
Get the default playback priority.
|
double |
getRate()
Get the default playback rate.
|
String |
getSource()
Get the source URL used to create this
AudioClip. |
double |
getVolume()
Get the default volume level.
|
boolean |
isPlaying()
Indicate whether this
AudioClip is playing. |
DoubleProperty |
panProperty()
The relative "center" of the clip.
|
void |
play()
Play the
AudioClip using all the default parameters. |
void |
play(double volume)
Play the
AudioClip using all the default parameters except volume. |
void |
play(double volume,
double balance,
double rate,
double pan,
int priority)
Play the
AudioClip using the given parameters. |
IntegerProperty |
priorityProperty()
The relative priority of the clip with respect to other clips.
|
DoubleProperty |
rateProperty()
The relative rate at which the clip is played.
|
void |
setBalance(double balance)
Set the default balance level.
|
void |
setCycleCount(int count)
Set the default cycle count.
|
void |
setPan(double pan)
Set the default pan value.
|
void |
setPriority(int priority)
Set the default playback priority.
|
void |
setRate(double rate)
Set the default playback rate.
|
void |
setVolume(double value)
Set the default volume level.
|
void |
stop()
Immediately stop all playback of this
AudioClip. |
DoubleProperty |
volumeProperty()
The relative volume level at which the clip is played.
|
public DoubleProperty volumeProperty
getVolume(),
setVolume(double)public DoubleProperty balanceProperty
getBalance(),
setBalance(double)public DoubleProperty rateProperty
getRate(),
setRate(double)public DoubleProperty panProperty
getPan(),
setPan(double)public IntegerProperty priorityProperty
getPriority(),
setPriority(int)public IntegerProperty cycleCountProperty
play()
is called. A cycleCount of 1 plays exactly once, a cycleCount of 2
plays twice and so on. Valid range is 1 or more, but setting this to
INDEFINITE will cause the clip to continue looping
until stop() is called.getCycleCount(),
setCycleCount(int)public static final int INDEFINITE
cycleCount is set to this value, the
AudioClip will loop continuously until stopped. This value is
synonymous with MediaPlayer.INDEFINITE and
Animation.INDEFINITE, these values may be used
interchangeably.public AudioClip(String source)
AudioClip loaded from the supplied source URL.source - URL string from which to load the audio clip. This can be an
HTTP, file or jar source.NullPointerException - if the parameter is null.IllegalArgumentException - if the parameter violates
RFC 2396.MediaException - if there is some other problem loading the media.public String getSource()
AudioClip.public final void setVolume(double value)
value - new default volume level for this clipvolumepublic final double getVolume()
volumepublic DoubleProperty volumeProperty()
getVolume(),
setVolume(double)public void setBalance(double balance)
balance - new default balancebalancepublic double getBalance()
balancepublic DoubleProperty balanceProperty()
getBalance(),
setBalance(double)public void setRate(double rate)
rate - the new default playback rateratepublic double getRate()
ratepublic DoubleProperty rateProperty()
getRate(),
setRate(double)public void setPan(double pan)
pan - the new default pan valuepanpublic double getPan()
panpublic DoubleProperty panProperty()
getPan(),
setPan(double)public void setPriority(int priority)
priority - the new default playback priorityprioritypublic int getPriority()
prioritypublic IntegerProperty priorityProperty()
getPriority(),
setPriority(int)public void setCycleCount(int count)
count - the new default cycle count for this clipcycleCountpublic int getCycleCount()
cycleCountpublic IntegerProperty cycleCountProperty()
play()
is called. A cycleCount of 1 plays exactly once, a cycleCount of 2
plays twice and so on. Valid range is 1 or more, but setting this to
INDEFINITE will cause the clip to continue looping
until stop() is called.getCycleCount(),
setCycleCount(int)public void play()
AudioClip using all the default parameters.public void play(double volume)
AudioClip using all the default parameters except volume.
This method does not modify the clip's default parameters.volume - the volume level at which to play the clippublic void play(double volume,
double balance,
double rate,
double pan,
int priority)
AudioClip using the given parameters. Values outside
the ranges as specified by their associated properties are clamped.
This method does not modify the clip's default parameters.volume - 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.balance - Left/right balance or relative channel volumes for stereo
effects.rate - Playback rate multiplier. 1.0 will play at the normal
rate while 2.0 will double the rate.pan - 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.priority - Audio effect priority. Lower priority effects will be
dropped first if too many effects are trying to play simultaneously.public boolean isPlaying()
AudioClip is playing. If this returns true
then play() has been called at least once and it is still playing.public void stop()
AudioClip.Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.