| public class javax.sound.sampled AudioSystem
|
Java SE 6 |
AudioSystem class acts as the entry point to the
sampled-audio system resources. This class lets you query and
access the mixers that are installed on the system.
AudioSystem includes a number of
methods for converting audio data between different formats, and for
translating between audio files and streams. It also provides a method
for obtaining a Line directly from the
AudioSystem without dealing explicitly
with mixers.
Properties can be used to specify the default mixer
for specific line types.
Both system properties and a properties file are considered.
In the Sun reference implementation, the properties file is
"lib/sound.properties" in the JRE
directory. If a property exists both as a system property and in the
properties file, the system property takes precedence. If none is
specified, a suitable default is chosen among the available devices.
The syntax of the properties file is specified in
Properties.load. The
following table lists the available property keys and which methods
consider them:
| Property Key | Interface | Affected Method(s) |
|---|---|---|
javax.sound.sampled.Clip |
Clip |
#getLine, #getClip |
javax.sound.sampled.Port |
Port |
#getLine |
javax.sound.sampled.SourceDataLine |
SourceDataLine |
#getLine, #getSourceDataLine |
javax.sound.sampled.TargetDataLine |
TargetDataLine |
#getLine, #getTargetDataLine |
mixer provider class. The mixer name is matched against
the String returned by the getName
method of Mixer.Info.
Either the class name, or the mixer name may be omitted.
If only the class name is specified, the trailing hash mark
is optional.
If the provider class is specified, and it can be
successully retrieved from the installed providers, the list of
Mixer.Info objects is retrieved
from the provider. Otherwise, or when these mixers
do not provide a subsequent match, the list is retrieved
from #getMixerInfo to contain
all available Mixer.Info objects.
If a mixer name is specified, the resulting list of
Mixer.Info objects is searched:
the first one with a matching name, and whose
Mixer provides the
respective line interface, will be returned.
If no matching Mixer.Info object
is found, or the mixer name is not specified,
the first mixer from the resulting
list, which provides the respective line
interface, will be returned.
For example, the property javax.sound.sampled.Clip
with a value
"com.sun.media.sound.MixerProvider#SunClip"
will have the following consequences when
getLine is called requesting a Clip
instance:
if the class com.sun.media.sound.MixerProvider exists
in the list of installed mixer providers,
the first Clip from the first mixer with name
"SunClip" will be returned. If it cannot
be found, the first Clip from the first mixer
of the specified provider will be returned, regardless of name.
If there is none, the first Clip from the first
Mixer with name
"SunClip" in the list of all mixers
(as returned by getMixerInfo) will be returned,
or, if not found, the first Clip of the first
Mixerthat can be found in the list of all
mixers is returned.
If that fails, too, an IllegalArgumentException
is thrown.
| version | 1.83, 06/04/07 |
| since | 1.3 |
| See also | javax.sound.sampled.AudioFormat, javax.sound.sampled.AudioInputStream, javax.sound.sampled.Mixer, javax.sound.sampled.Line, javax.sound.sampled.Line.Info |
| Fields | |
|---|---|
| final public static int | NOT_SPECIFIED An integer that stands for an unknown numeric value. This value is appropriate only for signed quantities that do not normally take negative values. Examples include file sizes, frame sizes, buffer sizes, and sample rates. A number of Java Sound constructors accept a value of NOT_SPECIFIED for such parameters. Other
methods may also accept or return this value, as documented.
|
| Methods | |||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| public static int | write(AudioInputStream stream, AudioFileFormat.Type fileType, OutputStream out) throws IOException Details
Writes a stream of bytes representing an audio file of the specified file type
to the output stream provided. Some file types require that
the length be written into the file header; such files cannot be written from
start to finish unless the length is known in advance. An attempt
to write a file of such a type will fail with an IOException if the length in
the audio file type is AudioSystem.NOT_SPECIFIED.
| ||||||||||||||
| public static int | write(AudioInputStream stream, AudioFileFormat.Type fileType, File out) throws IOException Details
Writes a stream of bytes representing an audio file of the specified file type
to the external file provided.
| ||||||||||||||
| Properties | |||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| public static AudioFileFormat | getAudioFileFormat(InputStream stream) throws UnsupportedAudioFileException, IOException Details
Obtains the audio file format of the provided input stream. The stream must
point to valid audio file data. The implementation of this method may require
multiple parsers to examine the stream to determine whether they support it.
These parsers must be able to mark the stream, read enough data to determine whether they
support the stream, and, if not, reset the stream's read pointer to its original
position. If the input stream does not support these operations, this method may fail
with an IOException.
| ||||||||||||||||
| public static AudioFileFormat | getAudioFileFormat(URL url) throws UnsupportedAudioFileException, IOException Details
Obtains the audio file format of the specified URL. The URL must
point to valid audio file data.
| ||||||||||||||||
| public static AudioFileFormat | getAudioFileFormat(File file) throws UnsupportedAudioFileException, IOException Details
Obtains the audio file format of the specified File. The File must
point to valid audio file data.
| ||||||||||||||||
| public static AudioFileFormat.Type[] | getAudioFileTypes() Details
Obtains the file types for which file writing support is provided by the system.
| ||||||||||||||||
| public static AudioFileFormat.Type[] | getAudioFileTypes(AudioInputStream stream) Details
Obtains the file types that the system can write from the
audio input stream specified.
| ||||||||||||||||
| public static AudioInputStream | getAudioInputStream(AudioFormat.Encoding targetEncoding, AudioInputStream sourceStream) Details
Obtains an audio input stream of the indicated encoding, by converting the
provided audio input stream.
| ||||||||||||||||
| public static AudioInputStream | getAudioInputStream(AudioFormat targetFormat, AudioInputStream sourceStream) Details
Obtains an audio input stream of the indicated format, by converting the
provided audio input stream.
| ||||||||||||||||
| public static AudioInputStream | getAudioInputStream(InputStream stream) throws UnsupportedAudioFileException, IOException Details
Obtains an audio input stream from the provided input stream. The stream must
point to valid audio file data. The implementation of this method may
require multiple parsers to
examine the stream to determine whether they support it. These parsers must
be able to mark the stream, read enough data to determine whether they
support the stream, and, if not, reset the stream's read pointer to its original
position. If the input stream does not support these operation, this method may fail
with an IOException.
| ||||||||||||||||
| public static AudioInputStream | getAudioInputStream(URL url) throws UnsupportedAudioFileException, IOException Details
Obtains an audio input stream from the URL provided. The URL must
point to valid audio file data.
| ||||||||||||||||
| public static AudioInputStream | getAudioInputStream(File file) throws UnsupportedAudioFileException, IOException Details
Obtains an audio input stream from the provided File. The File must
point to valid audio file data.
| ||||||||||||||||
| public static Clip | getClip() throws LineUnavailableException Details
Obtains a clip that can be used for playing back
an audio file or an audio stream. The returned clip
will be provided by the default system mixer, or,
if not possible, by any other mixer installed in the
system that supports a Clip
object.
The returned clip must be opened with the
This is a high-level method that uses If the system property
| ||||||||||||||||
| public static Clip | getClip(Mixer.Info mixerInfo) throws LineUnavailableException Details
Obtains a clip from the specified mixer that can be
used for playing back an audio file or an audio stream.
The returned clip must be opened with the
This is a high-level method that uses
| ||||||||||||||||
| public static boolean | isConversionSupported(AudioFormat.Encoding targetEncoding, AudioFormat sourceFormat) Details
Indicates whether an audio input stream of the specified encoding
can be obtained from an audio input stream that has the specified
format.
| ||||||||||||||||
| public static boolean | isConversionSupported(AudioFormat targetFormat, AudioFormat sourceFormat) Details
Indicates whether an audio input stream of a specified format
can be obtained from an audio input stream of another specified format.
| ||||||||||||||||
| public static boolean | isFileTypeSupported(AudioFileFormat.Type fileType) Details
Indicates whether file writing support for the specified file type is provided
by the system.
| ||||||||||||||||
| public static boolean | isFileTypeSupported(AudioFileFormat.Type fileType, AudioInputStream stream) Details
Indicates whether an audio file of the specified file type can be written
from the indicated audio input stream.
| ||||||||||||||||
| public static Line | getLine(Line.Info info) throws LineUnavailableException Details
Obtains a line that matches the description in the specified
Line.Info object.
If a If system properties
| ||||||||||||||||
| public static boolean | isLineSupported(Line.Info info) Details
Indicates whether the system supports any lines that match
the specified Line.Info object. A line is supported if
any installed mixer supports it.
| ||||||||||||||||
| public static Mixer | getMixer(Mixer.Info info) Details
Obtains the requested audio mixer.
| ||||||||||||||||
| public static Mixer.Info[] | getMixerInfo() Details
Obtains an array of mixer info objects that represents
the set of audio mixers that are currently installed on the system.
| ||||||||||||||||
| public static SourceDataLine | getSourceDataLine(AudioFormat format) throws LineUnavailableException Details
Obtains a source data line that can be used for playing back
audio data in the format specified by the
AudioFormat object. The returned line
will be provided by the default system mixer, or,
if not possible, by any other mixer installed in the
system that supports a matching
SourceDataLine object.
The returned line should be opened with the
This is a high-level method that uses The returned If the system property
| ||||||||||||||||
| public static SourceDataLine | getSourceDataLine(AudioFormat format, Mixer.Info mixerinfo) throws LineUnavailableException Details
Obtains a source data line that can be used for playing back
audio data in the format specified by the
AudioFormat object, provided by the mixer
specified by the Mixer.Info object.
The returned line should be opened with the
This is a high-level method that uses The returned
| ||||||||||||||||
| public static Line.Info[] | getSourceLineInfo(Line.Info info) Details
Obtains information about all source lines of a particular type that are supported
by the installed mixers.
| ||||||||||||||||
| public static TargetDataLine | getTargetDataLine(AudioFormat format) throws LineUnavailableException Details
Obtains a target data line that can be used for recording
audio data in the format specified by the
AudioFormat object. The returned line
will be provided by the default system mixer, or,
if not possible, by any other mixer installed in the
system that supports a matching
TargetDataLine object.
The returned line should be opened with the
This is a high-level method that uses The returned
| ||||||||||||||||
| public static TargetDataLine | getTargetDataLine(AudioFormat format, Mixer.Info mixerinfo) throws LineUnavailableException Details
Obtains a target data line that can be used for recording
audio data in the format specified by the
AudioFormat object, provided by the mixer
specified by the Mixer.Info object.
The returned line should be opened with the
This is a high-level method that uses The returned If the system property
| ||||||||||||||||
| public static AudioFormat.Encoding[] | getTargetEncodings(AudioFormat.Encoding sourceEncoding) Details
Obtains the encodings that the system can obtain from an
audio input stream with the specified encoding using the set
of installed format converters.
| ||||||||||||||||
| public static AudioFormat.Encoding[] | getTargetEncodings(AudioFormat sourceFormat) Details
Obtains the encodings that the system can obtain from an
audio input stream with the specified format using the set
of installed format converters.
| ||||||||||||||||
| public static AudioFormat[] | getTargetFormats(AudioFormat.Encoding targetEncoding, AudioFormat sourceFormat) Details
Obtains the formats that have a particular encoding and that the system can
obtain from a stream of the specified format using the set of
installed format converters.
| ||||||||||||||||
| public static Line.Info[] | getTargetLineInfo(Line.Info info) Details
Obtains information about all target lines of a particular type that are supported
by the installed mixers.
| ||||||||||||||||
| About DocWeb · Bundles · Export · Export All | Top 10 · Statistics · Login |
| About Sun · Contact · Privacy · Terms of Use · Trademarks | Java SE 6 · Copyright © 1994-2013 Sun Microsystems, Inc.All rights reserved. Use is subject to license terms |
![]() |
![]() |
|