javax.sound.sampled

Class AudioSystem

public class AudioSystem extends Object

This clas is the primary interface to the audio system. It contains a number of static methods which can be used to access this package's functionality.

Since: 1.3

Field Summary
static intNOT_SPECIFIED
A constant which can be passed to a number of methods in this package, to indicate an unspecified value.
Method Summary
static AudioFileFormatgetAudioFileFormat(File f)
Return the file format of a given File.
static AudioFileFormatgetAudioFileFormat(InputStream is)
Return the file format of a given input stream.
static AudioFileFormatgetAudioFileFormat(URL url)
Return the file format of a given URL.
static AudioFileFormat.Type[]getAudioFileTypes()
Return an array of all the supported AudioFileFormat types.
static AudioFileFormat.Type[]getAudioFileTypes(AudioInputStream ais)
Return an array of all the supported AudioFileFormat types which match the given audio input stream
static AudioInputStreamgetAudioInputStream(AudioFormat.Encoding targ, AudioInputStream ais)
Given an audio input stream, this will try to create a new audio input stream whose encoding matches the given target encoding.
static AudioInputStreamgetAudioInputStream(AudioFormat targ, AudioInputStream ais)
Given an audio input stream, this will try to create a new audio input stream whose format matches the given target format.
static AudioInputStreamgetAudioInputStream(File f)
Return an audio input stream for the file.
static AudioInputStreamgetAudioInputStream(InputStream is)
Return an audio input stream given an input stream.
static AudioInputStreamgetAudioInputStream(URL url)
Return an audio input stream for the given URL.
static ClipgetClip()
Return a new clip which can be used for playing back an audio stream.
static ClipgetClip(Mixer.Info info)
Return a new clip which can be used for playing back an audio stream.
static LinegetLine(Line.Info info)
Return a line matching the provided description.
static MixergetMixer(Mixer.Info info)
Return a mixer matching the provided description.
static Mixer.Info[]getMixerInfo()
Return an array of descriptions of all the mixers provided on the system.
static SourceDataLinegetSourceDataLine(AudioFormat fmt)
Return a source data line matching the given audio format.
static SourceDataLinegetSourceDataLine(AudioFormat fmt, Mixer.Info mixer)
Return a target data line matching the given audio format.
static Line.Info[]getSourceLineInfo(Line.Info info)
Return an array of descriptions of all the source lines matching the given line description.
static TargetDataLinegetTargetDataLine(AudioFormat fmt)
Find and return a target data line matching the given audio format.
static TargetDataLinegetTargetDataLine(AudioFormat fmt, Mixer.Info mixer)
Return a target data line matching the given audio format and mixer.
static AudioFormat.Encoding[]getTargetEncodings(AudioFormat.Encoding source)
Given a source encoding, return an array of all target encodings to which data in this form can be converted.
static AudioFormat.Encoding[]getTargetEncodings(AudioFormat source)
Given a source format, return an array of all the target encodings to which data in this format can be converted.
static AudioFormat[]getTargetFormats(AudioFormat.Encoding encoding, AudioFormat sourceFmt)
Given a target encoding and a source audio format, return an array of all matching audio formats to which data in this source format can be converted.
static Line.Info[]getTargetLineInfo(Line.Info info)
Given a line description, return an array of descriptions of all the matching target lines.
static booleanisConversionSupported(AudioFormat.Encoding targ, AudioFormat source)
Return true if the currently installed providers are able to convert data from the given source format to the given target encoding.
static booleanisConversionSupported(AudioFormat targ, AudioFormat source)
Return true if the currently installed providers are able to convert the given source format to the given target format.
static booleanisFileTypeSupported(AudioFileFormat.Type type)
Return true if the given audio file format is supported by one of the providers installed on the system.
static booleanisFileTypeSupported(AudioFileFormat.Type type, AudioInputStream ais)
Return true if the given audio file format is supported for the given audio input stream by one of the providers installed on the system.
static booleanisLineSupported(Line.Info info)
Return true if some provider on the system supplies a line matching the argument.
static intwrite(AudioInputStream ais, AudioFileFormat.Type type, File out)
Write an audio input stream to the given file, using the specified audio file format.
static intwrite(AudioInputStream ais, AudioFileFormat.Type type, OutputStream os)
Write an audio input stream to the given output stream, using the specified audio file format.

Field Detail

NOT_SPECIFIED

public static final int NOT_SPECIFIED
A constant which can be passed to a number of methods in this package, to indicate an unspecified value.

Method Detail

getAudioFileFormat

public static AudioFileFormat getAudioFileFormat(File f)
Return the file format of a given File.

Parameters: f the file to check

Returns: the format of the file

Throws: UnsupportedAudioFileException if the file's format is not recognized IOException if there is an I/O error reading the file

getAudioFileFormat

public static AudioFileFormat getAudioFileFormat(InputStream is)
Return the file format of a given input stream.

Parameters: is the input stream to check

Returns: the format of the stream

Throws: UnsupportedAudioFileException if the stream's format is not recognized IOException if there is an I/O error reading the stream

getAudioFileFormat

public static AudioFileFormat getAudioFileFormat(URL url)
Return the file format of a given URL.

Parameters: url the URL to check

Returns: the format of the URL

Throws: UnsupportedAudioFileException if the URL's format is not recognized IOException if there is an I/O error reading the URL

getAudioFileTypes

public static AudioFileFormat.Type[] getAudioFileTypes()
Return an array of all the supported AudioFileFormat types.

Returns: an array of unique types

getAudioFileTypes

public static AudioFileFormat.Type[] getAudioFileTypes(AudioInputStream ais)
Return an array of all the supported AudioFileFormat types which match the given audio input stream

Parameters: ais the audio input stream

Returns: an array of unique types

getAudioInputStream

public static AudioInputStream getAudioInputStream(AudioFormat.Encoding targ, AudioInputStream ais)
Given an audio input stream, this will try to create a new audio input stream whose encoding matches the given target encoding. If no provider offers this conversion, an exception is thrown.

Parameters: targ the target encoding ais the original audio stream

Returns: a new audio stream

Throws: IllegalArgumentException if the conversion cannot be made

getAudioInputStream

public static AudioInputStream getAudioInputStream(AudioFormat targ, AudioInputStream ais)
Given an audio input stream, this will try to create a new audio input stream whose format matches the given target format. If no provider offers this conversion, an exception is thrown.

Parameters: targ the target format ais the original audio stream

Returns: a new audio stream

Throws: IllegalArgumentException if the conversion cannot be made

getAudioInputStream

public static AudioInputStream getAudioInputStream(File f)
Return an audio input stream for the file.

Parameters: f the file to read

Returns: an audio input stream for the file

Throws: UnsupportedAudioFileException if the file's audio format is not recognized IOException if there is an error while reading the file

getAudioInputStream

public static AudioInputStream getAudioInputStream(InputStream is)
Return an audio input stream given an input stream.

Parameters: is the input stream

Returns: an audio input stream

Throws: UnsupportedAudioFileException if the input stream's audio format is not supported by any of the installed providers IOException if there is an error while reading the input stream

getAudioInputStream

public static AudioInputStream getAudioInputStream(URL url)
Return an audio input stream for the given URL.

Parameters: url the URL

Returns: an audio input stream

Throws: UnsupportedAudioFileException if the URL's audio format is not supported by any of the installed providers IOException if there is an error while reading the URL

getClip

public static Clip getClip()
Return a new clip which can be used for playing back an audio stream.

Throws: LineUnavailableException if a clip is not available for some reason SecurityException if a clip cannot be made for security reasons

Since: 1.5

getClip

public static Clip getClip(Mixer.Info info)
Return a new clip which can be used for playing back an audio stream. The clip is obtained from the indicated mixer.

Parameters: info the mixer to use

Throws: LineUnavailableException if a clip is not available for some reason SecurityException if a clip cannot be made for security reasons

Since: 1.5

getLine

public static Line getLine(Line.Info info)
Return a line matching the provided description. All the providers on the system are searched for a matching line.

Parameters: info description of the line

Returns: the matching line

Throws: LineUnavailableException if no provider supplies a matching line

getMixer

public static Mixer getMixer(Mixer.Info info)
Return a mixer matching the provided description. All the providers on the system are searched for a matching mixer.

Parameters: info description of the mixer

Returns: the matching mixer

Throws: IllegalArgumentException if no provider supplies a matching mixer

getMixerInfo

public static Mixer.Info[] getMixerInfo()
Return an array of descriptions of all the mixers provided on the system.

getSourceDataLine

public static SourceDataLine getSourceDataLine(AudioFormat fmt)
Return a source data line matching the given audio format.

Parameters: fmt the audio format

Throws: LineUnavailableException if no source data line matching this format is available

Since: 1.5

getSourceDataLine

public static SourceDataLine getSourceDataLine(AudioFormat fmt, Mixer.Info mixer)
Return a target data line matching the given audio format.

Parameters: fmt the audio format

Throws: LineUnavailableException if no target data line matching this format is available

Since: 1.5

getSourceLineInfo

public static Line.Info[] getSourceLineInfo(Line.Info info)
Return an array of descriptions of all the source lines matching the given line description.

Parameters: info description of the lines to match

getTargetDataLine

public static TargetDataLine getTargetDataLine(AudioFormat fmt)
Find and return a target data line matching the given audio format.

Parameters: fmt the format to match

Throws: LineUnavailableException if no matching line was found

Since: 1.5

getTargetDataLine

public static TargetDataLine getTargetDataLine(AudioFormat fmt, Mixer.Info mixer)
Return a target data line matching the given audio format and mixer.

Parameters: fmt the audio format mixer the mixer description

Returns: a target data line

Throws: LineUnavailableException if no matching target data line was found

Since: 1.5

getTargetEncodings

public static AudioFormat.Encoding[] getTargetEncodings(AudioFormat.Encoding source)
Given a source encoding, return an array of all target encodings to which data in this form can be converted.

Parameters: source the source encoding

getTargetEncodings

public static AudioFormat.Encoding[] getTargetEncodings(AudioFormat source)
Given a source format, return an array of all the target encodings to which data in this format can be converted.

Parameters: source the source format

getTargetFormats

public static AudioFormat[] getTargetFormats(AudioFormat.Encoding encoding, AudioFormat sourceFmt)
Given a target encoding and a source audio format, return an array of all matching audio formats to which data in this source format can be converted.

Parameters: encoding the target encoding sourceFmt the source format

getTargetLineInfo

public static Line.Info[] getTargetLineInfo(Line.Info info)
Given a line description, return an array of descriptions of all the matching target lines.

Parameters: info the line description

isConversionSupported

public static boolean isConversionSupported(AudioFormat.Encoding targ, AudioFormat source)
Return true if the currently installed providers are able to convert data from the given source format to the given target encoding.

Parameters: targ the target encoding source the source format

isConversionSupported

public static boolean isConversionSupported(AudioFormat targ, AudioFormat source)
Return true if the currently installed providers are able to convert the given source format to the given target format.

Parameters: targ the target format source the source format

isFileTypeSupported

public static boolean isFileTypeSupported(AudioFileFormat.Type type)
Return true if the given audio file format is supported by one of the providers installed on the system.

Parameters: type the audio file format type

isFileTypeSupported

public static boolean isFileTypeSupported(AudioFileFormat.Type type, AudioInputStream ais)
Return true if the given audio file format is supported for the given audio input stream by one of the providers installed on the system.

Parameters: type the audio file format type ais the audio input stream

isLineSupported

public static boolean isLineSupported(Line.Info info)
Return true if some provider on the system supplies a line matching the argument.

Parameters: info the line to match

write

public static int write(AudioInputStream ais, AudioFileFormat.Type type, File out)
Write an audio input stream to the given file, using the specified audio file format. All the providers installed on the system will be searched to find one that supports this operation.

Parameters: ais the audio input stream to write type the desired audio file format type out the file to write to

Returns: the number of bytes written

Throws: IOException if an I/O error occurs while writing IllegalArgumentException if the file type is not supported

write

public static int write(AudioInputStream ais, AudioFileFormat.Type type, OutputStream os)
Write an audio input stream to the given output stream, using the specified audio file format. All the providers installed on the system will be searched to find one that supports this operation.

Parameters: ais the audio input stream to write type the desired audio file format type os the output stream to write to

Returns: the number of bytes written

Throws: IOException if an I/O error occurs while writing IllegalArgumentException if the file type is not supported