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. AudioClip
s 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 |
---|---|
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() |
IntegerProperty |
cycleCountProperty() |
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() |
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() |
DoubleProperty |
rateProperty() |
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() |
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, HTTPS, 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 clipvolumeProperty()
public final double getVolume()
volumeProperty()
public DoubleProperty volumeProperty()
public void setBalance(double balance)
balance
- new default balancebalanceProperty()
public double getBalance()
balanceProperty()
public DoubleProperty balanceProperty()
public void setRate(double rate)
rate
- the new default playback raterateProperty()
public double getRate()
rateProperty()
public DoubleProperty rateProperty()
public void setPan(double pan)
pan
- the new default pan valuepanProperty()
public double getPan()
panProperty()
public DoubleProperty panProperty()
public void setPriority(int priority)
priority
- the new default playback prioritypriorityProperty()
public int getPriority()
priorityProperty()
public IntegerProperty priorityProperty()
public void setCycleCount(int count)
count
- the new default cycle count for this clipcycleCountProperty()
public int getCycleCount()
cycleCountProperty()
public IntegerProperty cycleCountProperty()
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 © 2020. All rights reserved.