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. The
"sound.properties" properties file is read from an implementation-specific
location (typically it is the conf directory in the Java installation
directory). The optional "javax.sound.config.file" system property can be
used to specify the properties file that will be read as the initial
configuration. 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.. 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 successfully 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 Mixer that can be found in the list
of all mixers is returned. If that fails, too, an
IllegalArgumentException is thrown.
AudioFormat, AudioInputStream, Mixer, Line, Line.Info
| Modifier and Type | Field and Description |
|---|---|
| public static final int | NOT_SPECIFIED
An integer that stands for an unknown numeric value. |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static AudioFileFormat | Returns: anAudioFileFormat object describing the stream's audio
file formatthe input stream from which file format information should
be extracted stream)Obtains the audio file format of the provided input stream. |
| public static AudioFileFormat | Returns: anAudioFileFormat object describing the audio file
formatthe url)URL from which file format information should be
extractedObtains the audio file format of the specified |
| public static AudioFileFormat | Returns: anAudioFileFormat object describing the audio file
formatthe file)File from which file format information should
be extractedObtains the audio file format of the specified |
| private static List | Returns: a List ofAudioFileReader objects representing the
installed audio file readers. If no audio file readers are
available on the system, an empty List is returned.Obtains the set of audio file readers that are currently installed on the system. |
| public static AudioFileFormat. | Returns: array of unique file types. If no file types are supported, an array of length 0 is returned.Obtains the file types for which file writing support is provided by the system. |
| public static AudioFileFormat. | Returns: array of file types. If no file types are supported, an array of length 0 is returned.the audio input stream for which audio file type support
is queried stream)Obtains the file types that the system can write from the audio input stream specified. |
| private static List | Returns: a List ofAudioFileWriter objects representing the
available audio file writers. If no audio file writers are
available on the system, an empty List is returned.Obtains the set of audio file writers that are currently installed on the system. |
| public static AudioInputStream | Returns: an audio input stream of the indicated encodingthe desired encoding after conversion targetEncoding,the stream to be converted sourceStream)Obtains an audio input stream of the indicated encoding, by converting the provided audio input stream. |
| public static AudioInputStream | Returns: an audio input stream of the indicated formatthe desired audio format after conversion targetFormat, AudioInputStream the stream to be converted sourceStream)Obtains an audio input stream of the indicated format, by converting the provided audio input stream. |
| public static AudioInputStream | Returns: anAudioInputStream object based on the audio file data
contained in the input streamthe input stream from which the stream)AudioInputStream
should be constructedObtains an audio input stream from the provided input stream. |
| public static AudioInputStream | Returns: anAudioInputStream object based on the audio file data
pointed to by the URLthe url)URL for which the AudioInputStream should
be constructedObtains an audio input stream from the |
| public static AudioInputStream | Returns: anAudioInputStream object based on the audio file data
pointed to by the Filethe file)File for which the AudioInputStream
should be constructedObtains an audio input stream from the provided |
| public static Clip | Returns: the desired clip objectObtains a clip that can be used for playing back an audio file or an audio stream. |
| public static Clip | |
| private static Mixer | Returns: a Mixer that matches the requirements, or null if no default mixer foundthe installed mixer providers providers, Line.The requested line type TargetDataLine.class, Clip.class or
Port.class infoAttempts to locate and return a default Mixer that provides lines of the specified type. |
| private static Mixer | Returns: A Mixer that is considered appropriate, or null if none is foundThe MixerProvider to check for Mixers provider, Line.The type of line the returned Mixer is required to support info,If true, only Mixers that support mixing are
returned for line types of SourceDataLine and Clip isMixingRequired)From a given MixerProvider, return the first appropriate Mixer. |
| private static List | Returns: an array ofFormatConversionProvider objects representing
the available format converters. If no format converters readers
are available on the system, an array of length 0 is returned.Obtains the set of format converters (codecs, transcoders, etc.) that are currently installed on the system. |
| public static Line | |
| public static Mixer | |
| public static Mixer. | Returns: an array of info objects for the currently installed mixers. If no mixers are available on the system, an array of length 0 is returned.Obtains an array of mixer info objects that represents the set of audio mixers that are currently installed on the system. |
| private static List | Returns: a List of info objects for the currently installed mixers. If no mixers are available on the system, an empty List is returned.Like getMixerInfo, but return List. |
| private static List | Returns: a List of info objects for the currently installed mixers. If no mixers are available on the system, an empty List is returned.The list of MixerProviders providers)Like getMixerInfo, but return List. |
| private static List | Returns: the list of MixerProviders currently installed on the systemObtains the list of MixerProviders currently installed on the system. |
| private static Mixer | Returns: A Mixer matching the requirements, or null if none is foundThe name of the Mixer to be returned mixerName, MixerProvider The MixerProvider to check for Mixers provider, Line.The type of line the returned Mixer is required to support infoReturn a Mixer with a given name from a given MixerProvider. |
| private static Mixer | Returns: A Mixer matching the requirements, or null if none is foundThe name of the Mixer to be returned mixerName, List<MixerProvider> The List of MixerProviders to check for Mixers providers, Line.The type of line the returned Mixer is required to support infoFrom a List of MixerProviders, return a Mixer with a given name. |
| private static MixerProvider | Returns: A MixerProvider of the requested class, or null if none is foundThe class name of the provider to be returned providerClassName, List<MixerProvider> The list of MixerProviders that is searched providers)Return a MixerProvider of a given class from the list of MixerProviders. |
| private static List | Returns: a List of instances of providers for the requested service. If no providers are available, a vector of length 0 will be returned.The type of providers requested. This should be one
of AudioFileReader.class, AudioFileWriter.class,
FormatConversionProvider.class, MixerProvider.class,
MidiDeviceProvider.class, MidiFileReader.class,
MidiFileWriter.class or SoundbankReader.class. providerClass)Obtains the set of services currently installed on the system using the SPI mechanism in 1.3. |
| public static SourceDataLine | Returns: the desiredSourceDataLine objectan format)AudioFormat object specifying the supported
audio format of the returned line, or null for any audio
formatObtains a source data line that can be used for playing back audio data
in the format specified by the |
| public static SourceDataLine | Returns: the desiredSourceDataLine objectan format, Mixer.AudioFormat object specifying the supported
audio format of the returned line, or null for any audio
formata mixerinfoMixer.Info object representing the desired
mixer, or null for the system default mixerObtains a source data line that can be used for playing back audio data
in the format specified by the |
| public static Line. | Returns: an array ofLine.Info objects describing source lines
matching the type requested. If no matching source lines are
supported, an array of length 0 is returned.a infoLine.Info object that specifies the kind of lines
about which information is requestedObtains information about all source lines of a particular type that are supported by the installed mixers. |
| public static TargetDataLine | Returns: the desiredTargetDataLine objectan format)AudioFormat object specifying the supported
audio format of the returned line, or null for any audio
formatObtains a target data line that can be used for recording audio data in
the format specified by the |
| public static TargetDataLine | Returns: the desiredTargetDataLine objectan format, Mixer.AudioFormat object specifying the supported
audio format of the returned line, or null for any audio
formata mixerinfoMixer.Info object representing the desired
mixer, or null for the system default mixerObtains a target data line that can be used for recording audio data in
the format specified by the |
| public static AudioFormat. | Returns: array of encodings. IfsourceEncoding is not supported,
an array of length 0 is returned. Otherwise, the array will have
a length of at least 1, representing sourceEncoding
(no conversion).the encoding for which conversion support is
queried sourceEncodingObtains 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. | Returns: array of encodings. IfsourceFormatis not supported, an
array of length 0 is returned. Otherwise, the array will have a
length of at least 1, representing the encoding of
sourceFormat (no conversion).the audio format for which conversion is queried sourceFormat)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[] | Returns: array of formats. If no formats of the specified encoding are supported, an array of length 0 is returned.the desired encoding after conversion targetEncoding,the audio format before conversion sourceFormat)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. | Returns: an array ofLine.Info objects describing target lines
matching the type requested. If no matching target lines are
supported, an array of length 0 is returned.a infoLine.Info object that specifies the kind of lines
about which information is requestedObtains information about all target lines of a particular type that are supported by the installed mixers. |
| private static boolean | Returns: true if the mixer is considered appropriate according to
the rules given above, false otherwiseThe mixer to check mixer, Line.The line to check lineInfo,Is the mixing required or not isMixingRequired)Checks if a Mixer is appropriate. |
| public static boolean | Returns: true if the conversion is supported, otherwise
falsethe desired encoding after conversion targetEncoding,the audio format before conversion sourceFormat)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 | Returns: true if the conversion is supported, otherwise
falsethe desired audio format after conversion targetFormat, AudioFormat the audio format before conversion sourceFormat)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 | Returns: true if the file type is supported, otherwise
falsethe file type for which write capabilities are queried fileTypeIndicates whether file writing support for the specified file type is provided by the system. |
| public static boolean | Returns: true if the file type is supported for this audio input
stream, otherwise falsethe file type for which write capabilities are queried fileType,the stream for which file-writing support is queried stream)Indicates whether an audio file of the specified file type can be written from the indicated audio input stream. |
| public static boolean | Returns: true if at least one matching line is supported,
otherwise falsea infoLine.Info object describing the line for which
support is queriedIndicates whether the system supports any lines that match the specified
|
| public static int | Returns: the number of bytes written to the output streamthe audio input stream containing audio data to be written
to the file stream, final AudioFileFormat.the kind of audio file to write fileType,the stream to which the file data should be written out)Writes a stream of bytes representing an audio file of the specified file type to the output stream provided. |
| public static int | Returns: the number of bytes written to the filethe audio input stream containing audio data to be written
to the file stream, final AudioFileFormat.the kind of audio file to write fileType,the external file to which the file data should be written out)Writes a stream of bytes representing an audio file of the specified file type to the external file provided. |