-
- All Superinterfaces:
- AutoCloseable, DataLine, Line
public interface Clip extends DataLine
TheClip
interface represents a special kind of data line whose audio data can be loaded prior to playback, instead of being streamed in real time.Because the data is pre-loaded and has a known length, you can set a clip to start playing at any position in its audio data. You can also create a loop, so that when the clip is played it will cycle repeatedly. Loops are specified with a starting and ending sample frame, along with the number of times that the loop should be played.
Clips may be obtained from a
that supports lines of this type. Data is loaded into a clip when it is opened.Mixer
Playback of an audio clip may be started and stopped using the
start
andstop
methods. These methods do not reset the media position;start
causes playback to continue from the position where playback was last stopped. To restart playback from the beginning of the clip's audio data, simply follow the invocation of
with setFramePosition(0), which rewinds the media to the beginning of the clip.stop
- Since:
- 1.3
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface javax.sound.sampled.DataLine
DataLine.Info
-
-
Field Summary
Fields Modifier and Type Field and Description static int
LOOP_CONTINUOUSLY
A value indicating that looping should continue indefinitely rather than complete after a specific number of loops.
-
Method Summary
Methods Modifier and Type Method and Description int
getFrameLength()
Obtains the media length in sample frames.long
getMicrosecondLength()
Obtains the media duration in microsecondsvoid
loop(int count)
Starts looping playback from the current position.void
open(AudioFormat format, byte[] data, int offset, int bufferSize)
Opens the clip, meaning that it should acquire any required system resources and become operational.void
open(AudioInputStream stream)
Opens the clip with the format and audio data present in the provided audio input stream.void
setFramePosition(int frames)
Sets the media position in sample frames.void
setLoopPoints(int start, int end)
Sets the first and last sample frames that will be played in the loop.void
setMicrosecondPosition(long microseconds)
Sets the media position in microseconds.-
Methods inherited from interface javax.sound.sampled.DataLine
available, drain, flush, getBufferSize, getFormat, getFramePosition, getLevel, getLongFramePosition, getMicrosecondPosition, isActive, isRunning, start, stop
-
Methods inherited from interface javax.sound.sampled.Line
addLineListener, close, getControl, getControls, getLineInfo, isControlSupported, isOpen, open, removeLineListener
-
-
-
-
Field Detail
-
LOOP_CONTINUOUSLY
static final int LOOP_CONTINUOUSLY
A value indicating that looping should continue indefinitely rather than complete after a specific number of loops.- See Also:
loop(int)
, Constant Field Values
-
-
Method Detail
-
open
void open(AudioFormat format, byte[] data, int offset, int bufferSize) throws LineUnavailableException
Opens the clip, meaning that it should acquire any required system resources and become operational. The clip is opened with the format and audio data indicated. If this operation succeeds, the line is marked as open and an
event is dispatched to the line's listeners.OPEN
Invoking this method on a line which is already open is illegal and may result in an IllegalStateException.
Note that some lines, once closed, cannot be reopened. Attempts to reopen such a line will always result in a
.LineUnavailableException
- Parameters:
format
- the format of the supplied audio datadata
- a byte array containing audio data to load into the clipoffset
- the point at which to start copying, expressed in bytes from the beginning of the arraybufferSize
- the number of bytes of data to load into the clip from the array.- Throws:
LineUnavailableException
- if the line cannot be opened due to resource restrictionsIllegalArgumentException
- if the buffer size does not represent an integral number of sample frames, or ifformat
is not fully specified or invalidIllegalStateException
- if the line is already openSecurityException
- if the line cannot be opened due to security restrictions- See Also:
Line.close()
,Line.isOpen()
,LineListener
-
open
void open(AudioInputStream stream) throws LineUnavailableException, IOException
Opens the clip with the format and audio data present in the provided audio input stream. Opening a clip means that it should acquire any required system resources and become operational. If this operation input stream. If this operation succeeds, the line is marked open and an
event is dispatched to the line's listeners.OPEN
Invoking this method on a line which is already open is illegal and may result in an IllegalStateException.
Note that some lines, once closed, cannot be reopened. Attempts to reopen such a line will always result in a
.LineUnavailableException
- Parameters:
stream
- an audio input stream from which audio data will be read into the clip- Throws:
LineUnavailableException
- if the line cannot be opened due to resource restrictionsIOException
- if an I/O exception occurs during reading of the streamIllegalArgumentException
- if the stream's audio format is not fully specified or invalidIllegalStateException
- if the line is already openSecurityException
- if the line cannot be opened due to security restrictions- See Also:
Line.close()
,Line.isOpen()
,LineListener
-
getFrameLength
int getFrameLength()
Obtains the media length in sample frames.- Returns:
- the media length, expressed in sample frames,
or
AudioSystem.NOT_SPECIFIED
if the line is not open. - See Also:
AudioSystem.NOT_SPECIFIED
-
getMicrosecondLength
long getMicrosecondLength()
Obtains the media duration in microseconds- Returns:
- the media duration, expressed in microseconds,
or
AudioSystem.NOT_SPECIFIED
if the line is not open. - See Also:
AudioSystem.NOT_SPECIFIED
-
setFramePosition
void setFramePosition(int frames)
Sets the media position in sample frames. The position is zero-based; the first frame is frame number zero. When the clip begins playing the next time, it will start by playing the frame at this position.To obtain the current position in sample frames, use the
method ofgetFramePosition
DataLine
.- Parameters:
frames
- the desired new media position, expressed in sample frames
-
setMicrosecondPosition
void setMicrosecondPosition(long microseconds)
Sets the media position in microseconds. When the clip begins playing the next time, it will start at this position. The level of precision is not guaranteed. For example, an implementation might calculate the microsecond position from the current frame position and the audio sample frame rate. The precision in microseconds would then be limited to the number of microseconds per sample frame.To obtain the current position in microseconds, use the
method ofgetMicrosecondPosition
DataLine
.- Parameters:
microseconds
- the desired new media position, expressed in microseconds
-
setLoopPoints
void setLoopPoints(int start, int end)
Sets the first and last sample frames that will be played in the loop. The ending point must be greater than or equal to the starting point, and both must fall within the the size of the loaded media. A value of 0 for the starting point means the beginning of the loaded media. Similarly, a value of -1 for the ending point indicates the last frame of the media.- Parameters:
start
- the loop's starting position, in sample frames (zero-based)end
- the loop's ending position, in sample frames (zero-based), or -1 to indicate the final frame- Throws:
IllegalArgumentException
- if the requested loop points cannot be set, usually because one or both falls outside the media's duration or because the ending point is before the starting point
-
loop
void loop(int count)
Starts looping playback from the current position. Playback will continue to the loop's end point, then loop back to the loop start pointcount
times, and finally continue playback to the end of the clip.If the current position when this method is invoked is greater than the loop end point, playback simply continues to the end of the clip without looping.
A
count
value of 0 indicates that any current looping should cease and playback should continue to the end of the clip. The behavior is undefined when this method is invoked with any other value during a loop operation.If playback is stopped during looping, the current loop status is cleared; the behavior of subsequent loop and start requests is not affected by an interrupted loop operation.
- Parameters:
count
- the number of times playback should loop back from the loop's end position to the loop's start position, or
to indicate that looping should continue until interruptedLOOP_CONTINUOUSLY
-
-
Traduction non disponible
Les API Java ne sont pas encore traduites en français sur l'infobrol. Seule la version anglaise est disponible pour l'instant.
Version en cache
22/11/2024 03:06:35 Cette version de la page est en cache (à la date du 22/11/2024 03:06:35) afin d'accélérer le traitement. Vous pouvez activer le mode utilisateur dans le menu en haut pour afficher la dernère version de la page.Document créé le 29/08/2006, dernière modification le 04/03/2020
Source du document imprimé : https://www.gaudry.be/java-api-rf-javax/sound/sampled/Clip.html
L'infobrol est un site personnel dont le contenu n'engage que moi. Le texte est mis à disposition sous licence CreativeCommons(BY-NC-SA). Plus d'info sur les conditions d'utilisation et sur l'auteur.
Références
Ces références et liens indiquent des documents consultés lors de la rédaction de cette page, ou qui peuvent apporter un complément d'information, mais les auteurs de ces sources ne peuvent être tenus responsables du contenu de cette page.
L'auteur de ce site est seul responsable de la manière dont sont présentés ici les différents concepts, et des libertés qui sont prises avec les ouvrages de référence. N'oubliez pas que vous devez croiser les informations de sources multiples afin de diminuer les risques d'erreurs.