SoundClip class is a simple abstraction for playing a sound clip.
It will play any format that is recognized by the javax.sound API,
and for which it has support. This includes midi data.
This class is intended for easy playback of short clips or snippets of sound. Examples of when this might be used is to play an audible alert or effect in a UI app, or to make a short announcement or to provide audible feedback such announcing as the function of a button or control. The application will typically let such clips play once to completion.
Applications needing more precise control or advanced
features should look into other parts of the javax.sound API.
Playing sound requires that the environment grants access to audio devices.
Typically this means running the application in a desktop environment.
Multiple SoundClip items can be playing at the same time, and
the resulting sound is mixed together to produce a composite.
| Modifier and Type | Field and Description |
|---|---|
| private final JavaSoundAudioClip |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | Returns: whether this is a playable sound clipReturns whether this is a playable sound clip. |
| public static SoundClip | Returns: aSoundClipthe file from which to obtain the sound data file)Creates a |
| public boolean | |
| public void | |
| public void | |
| public void |
| clip | back to summary |
|---|---|
| private final JavaSoundAudioClip clip | |
| SoundClip | back to summary |
|---|---|
| private SoundClip(File file) throws IOException | |
| canPlay | back to summary |
|---|---|
| public boolean canPlay() Returns whether this is a playable sound clip.
A value of
| |
| createSoundClip | back to summary |
|---|---|
| public static SoundClip createSoundClip(File file) throws IOException Creates a The file contents will be fully read before this method returns. If the file does not contain recognizable and supported sound data, or if the implementation does not find a suitable output device for the data, playing the clip will be a no-op.
| |
| isPlaying | back to summary |
|---|---|
| public boolean isPlaying() Returns whether sound is currently playing.
| |
| loop | back to summary |
|---|---|
| public void loop() Starts playing this sound clip in a loop. Each time this method is called, the clip is restarted from the beginning. This method will return immediately whether or not sound is played, and possibly before the sound has started playing.
Threading notes : Most applications will not need to do anything except call | |
| play | back to summary |
|---|---|
| public void play() Starts playing this sound clip. Each time this method is called, the clip is restarted from the beginning. This method will return immediately whether or not sound is played, and possibly before the sound has started playing.
Threading notes : Most applications will not need to do anything except call | |
| stop | back to summary |
|---|---|
| public void stop() Stops playing this sound clip.
Call this if the clip is playing and the application needs to stop
it early, for example so that the application can ensure the clip
playing does not block exit. It is also required to stop a | |