FileDocCategorySizeDatePackage
AudioSystem.javaAPI DocJava SE 6 API57986Tue Jun 10 00:26:30 BST 2008javax.sound.sampled

AudioSystem

public class AudioSystem extends Object
The 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 {@link 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 {@link java.util.Properties#load(InputStream) 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 {@link Clip} {@link #getLine}, {@link #getClip}
javax.sound.sampled.Port {@link Port} {@link #getLine}
javax.sound.sampled.SourceDataLine {@link SourceDataLine} {@link #getLine}, {@link #getSourceDataLine}
javax.sound.sampled.TargetDataLine {@link TargetDataLine} {@link #getLine}, {@link #getTargetDataLine}
The property value consists of the provider class name and the mixer name, separated by the hash mark ("#"). The provider class name is the fully-qualified name of a concrete {@link javax.sound.sampled.spi.MixerProvider 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 {@link #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.

author
Kara Kytle
author
Florian Bomers
author
Matthias Pfisterer
author
Kevin P. Smith
version
1.83, 06/04/07
see
AudioFormat
see
AudioInputStream
see
Mixer
see
Line
see
Line.Info
since
1.3

Fields Summary
public static final 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.
Constructors Summary
private AudioSystem()
Private no-args constructor for ensuring against instantiation.


                
      
    
Methods Summary
public static javax.sound.sampled.AudioFileFormatgetAudioFileFormat(java.io.InputStream stream)
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.

param
stream the input stream from which file format information should be extracted
return
an AudioFileFormat object describing the stream's audio file format
throws
UnsupportedAudioFileException if the stream does not point to valid audio file data recognized by the system
throws
IOException if an input/output exception occurs
see
InputStream#markSupported
see
InputStream#mark


	List providers = getAudioFileReaders();
	AudioFileFormat format = null;

	for(int i = 0; i < providers.size(); i++ ) {
	    AudioFileReader reader = (AudioFileReader) providers.get(i);
	    try {
		format = reader.getAudioFileFormat( stream ); // throws IOException
		break;
	    } catch (UnsupportedAudioFileException e) {
		continue;
	    }
	}

	if( format==null ) {
	    throw new UnsupportedAudioFileException("file is not a supported file type");
	} else {
	    return format;
	}
    
public static javax.sound.sampled.AudioFileFormatgetAudioFileFormat(java.net.URL url)
Obtains the audio file format of the specified URL. The URL must point to valid audio file data.

param
url the URL from which file format information should be extracted
return
an AudioFileFormat object describing the audio file format
throws
UnsupportedAudioFileException if the URL does not point to valid audio file data recognized by the system
throws
IOException if an input/output exception occurs


	List providers = getAudioFileReaders();
	AudioFileFormat format = null;

	for(int i = 0; i < providers.size(); i++ ) {
	    AudioFileReader reader = (AudioFileReader) providers.get(i);
	    try {
		format = reader.getAudioFileFormat( url ); // throws IOException
		break;
	    } catch (UnsupportedAudioFileException e) {
		continue;
	    }
	}

	if( format==null ) {
	    throw new UnsupportedAudioFileException("file is not a supported file type");
	} else {
	    return format;
	}
    
public static javax.sound.sampled.AudioFileFormatgetAudioFileFormat(java.io.File file)
Obtains the audio file format of the specified File. The File must point to valid audio file data.

param
file the File from which file format information should be extracted
return
an AudioFileFormat object describing the audio file format
throws
UnsupportedAudioFileException if the File does not point to valid audio file data recognized by the system
throws
IOException if an I/O exception occurs


	List providers = getAudioFileReaders();
	AudioFileFormat format = null;

	for(int i = 0; i < providers.size(); i++ ) {
	    AudioFileReader reader = (AudioFileReader) providers.get(i);
	    try {
		format = reader.getAudioFileFormat( file ); // throws IOException
		break;
	    } catch (UnsupportedAudioFileException e) {
		continue;
	    }
	}

	if( format==null ) {
	    throw new UnsupportedAudioFileException("file is not a supported file type");
	} else {
	    return format;
	}
    
private static java.util.ListgetAudioFileReaders()
Obtains the set of audio file readers that are currently installed on the system.

return
a List of {@link javax.sound.sampled.spi.AudioFileReader AudioFileReader} objects representing the installed audio file readers. If no audio file readers are available on the system, an empty List is returned.

	return getProviders(AudioFileReader.class);
    
public static javax.sound.sampled.AudioFileFormat$Type[]getAudioFileTypes()
Obtains the file types for which file writing support is provided by the system.

return
array of unique file types. If no file types are supported, an array of length 0 is returned.

	List providers = getAudioFileWriters();
	Set returnTypesSet = new HashSet();

	for(int i=0; i < providers.size(); i++) {
	    AudioFileWriter writer = (AudioFileWriter) providers.get(i);
	    AudioFileFormat.Type[] fileTypes = writer.getAudioFileTypes();
	    for(int j=0; j < fileTypes.length; j++) {
		returnTypesSet.add(fileTypes[j]);
	    }
	}
	AudioFileFormat.Type returnTypes[] = (AudioFileFormat.Type[])
	    returnTypesSet.toArray(new AudioFileFormat.Type[0]);
	return returnTypes;
    
public static javax.sound.sampled.AudioFileFormat$Type[]getAudioFileTypes(javax.sound.sampled.AudioInputStream stream)
Obtains the file types that the system can write from the audio input stream specified.

param
stream the audio input stream for which audio file type support is queried
return
array of file types. If no file types are supported, an array of length 0 is returned.

	List providers = getAudioFileWriters();
	Set returnTypesSet = new HashSet();

	for(int i=0; i < providers.size(); i++) {
	    AudioFileWriter writer = (AudioFileWriter) providers.get(i);
	    AudioFileFormat.Type[] fileTypes = writer.getAudioFileTypes(stream);
	    for(int j=0; j < fileTypes.length; j++) {
		returnTypesSet.add(fileTypes[j]);
	    }
	}
	AudioFileFormat.Type returnTypes[] = (AudioFileFormat.Type[])
	    returnTypesSet.toArray(new AudioFileFormat.Type[0]);
	return returnTypes;
    
private static java.util.ListgetAudioFileWriters()
Obtains the set of audio file writers that are currently installed on the system.

return
a List of {@link javax.sound.samples.spi.AudioFileWriter AudioFileWriter} objects representing the available audio file writers. If no audio file writers are available on the system, an empty List is returned.

	return getProviders(AudioFileWriter.class);
    
public static javax.sound.sampled.AudioInputStreamgetAudioInputStream(javax.sound.sampled.AudioFormat$Encoding targetEncoding, javax.sound.sampled.AudioInputStream sourceStream)
Obtains an audio input stream of the indicated encoding, by converting the provided audio input stream.

param
targetEncoding the desired encoding after conversion
param
sourceStream the stream to be converted
return
an audio input stream of the indicated encoding
throws
IllegalArgumentException if the conversion is not supported
see
#getTargetEncodings(AudioFormat.Encoding)
see
#getTargetEncodings(AudioFormat)
see
#isConversionSupported(AudioFormat.Encoding, AudioFormat)
see
#getAudioInputStream(AudioFormat, AudioInputStream)


	List codecs = getFormatConversionProviders();

	for(int i = 0; i < codecs.size(); i++) {
	    FormatConversionProvider codec = (FormatConversionProvider) codecs.get(i);
	    if( codec.isConversionSupported( targetEncoding, sourceStream.getFormat() ) ) {
		return codec.getAudioInputStream( targetEncoding, sourceStream );
	    }
	}
	// we ran out of options, throw an exception
	throw new IllegalArgumentException("Unsupported conversion: " + targetEncoding + " from " + sourceStream.getFormat());
    
public static javax.sound.sampled.AudioInputStreamgetAudioInputStream(javax.sound.sampled.AudioFormat targetFormat, javax.sound.sampled.AudioInputStream sourceStream)
Obtains an audio input stream of the indicated format, by converting the provided audio input stream.

param
targetFormat the desired audio format after conversion
param
sourceStream the stream to be converted
return
an audio input stream of the indicated format
throws
IllegalArgumentException if the conversion is not supported #see #getTargetEncodings(AudioFormat)
see
#getTargetFormats(AudioFormat.Encoding, AudioFormat)
see
#isConversionSupported(AudioFormat, AudioFormat)
see
#getAudioInputStream(AudioFormat.Encoding, AudioInputStream)


	if (sourceStream.getFormat().matches(targetFormat)) {
	    return sourceStream;
	}

	List codecs = getFormatConversionProviders();

	for(int i = 0; i < codecs.size(); i++) {
	    FormatConversionProvider codec = (FormatConversionProvider) codecs.get(i);
	    if(codec.isConversionSupported(targetFormat,sourceStream.getFormat()) ) {
		return codec.getAudioInputStream(targetFormat,sourceStream);
	    }
	}

	// we ran out of options...
	throw new IllegalArgumentException("Unsupported conversion: " + targetFormat + " from " + sourceStream.getFormat());
    
public static javax.sound.sampled.AudioInputStreamgetAudioInputStream(java.io.InputStream stream)
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.

param
stream the input stream from which the AudioInputStream should be constructed
return
an AudioInputStream object based on the audio file data contained in the input stream.
throws
UnsupportedAudioFileException if the stream does not point to valid audio file data recognized by the system
throws
IOException if an I/O exception occurs
see
InputStream#markSupported
see
InputStream#mark


	List providers = getAudioFileReaders();
	AudioInputStream audioStream = null;

	for(int i = 0; i < providers.size(); i++ ) {
	    AudioFileReader reader = (AudioFileReader) providers.get(i);
	    try {
		audioStream = reader.getAudioInputStream( stream ); // throws IOException
		break;
	    } catch (UnsupportedAudioFileException e) {
		continue;
	    }
	}

	if( audioStream==null ) {
	    throw new UnsupportedAudioFileException("could not get audio input stream from input stream");
	} else {
	    return audioStream;
	}
    
public static javax.sound.sampled.AudioInputStreamgetAudioInputStream(java.net.URL url)
Obtains an audio input stream from the URL provided. The URL must point to valid audio file data.

param
url the URL for which the AudioInputStream should be constructed
return
an AudioInputStream object based on the audio file data pointed to by the URL
throws
UnsupportedAudioFileException if the URL does not point to valid audio file data recognized by the system
throws
IOException if an I/O exception occurs


	List providers = getAudioFileReaders();
	AudioInputStream audioStream = null;

	for(int i = 0; i < providers.size(); i++ ) {
	    AudioFileReader reader = (AudioFileReader) providers.get(i);
	    try {
		audioStream = reader.getAudioInputStream( url ); // throws IOException
		break;
	    } catch (UnsupportedAudioFileException e) {
		continue;
	    }
	}

	if( audioStream==null ) {
	    throw new UnsupportedAudioFileException("could not get audio input stream from input URL");
	} else {
	    return audioStream;
	}
    
public static javax.sound.sampled.AudioInputStreamgetAudioInputStream(java.io.File file)
Obtains an audio input stream from the provided File. The File must point to valid audio file data.

param
file the File for which the AudioInputStream should be constructed
return
an AudioInputStream object based on the audio file data pointed to by the File
throws
UnsupportedAudioFileException if the File does not point to valid audio file data recognized by the system
throws
IOException if an I/O exception occurs


	List providers = getAudioFileReaders();
	AudioInputStream audioStream = null;

	for(int i = 0; i < providers.size(); i++ ) {
	    AudioFileReader reader = (AudioFileReader) providers.get(i);
	    try {
		audioStream = reader.getAudioInputStream( file ); // throws IOException
		break;
	    } catch (UnsupportedAudioFileException e) {
		continue;
	    }
	}

	if( audioStream==null ) {
	    throw new UnsupportedAudioFileException("could not get audio input stream from input file");
	} else {
	    return audioStream;
	}
    
public static javax.sound.sampled.ClipgetClip()
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 open(AudioFormat) or open(AudioInputStream) method.

This is a high-level method that uses getMixer and getLine internally.

If the system property javax.sound.sampled.Clip is defined or it is defined in the file "sound.properties", it is used to retrieve the default clip. For details, refer to the {@link AudioSystem class description}.

return
the desired clip object
throws
LineUnavailableException if a clip object is not available due to resource restrictions
throws
SecurityException if a clip object is not available due to security restrictions
throws
IllegalArgumentException if the system does not support at least one clip instance through any installed mixer
see
#getClip(Mixer.Info)
since
1.5

	AudioFormat format = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,
					     AudioSystem.NOT_SPECIFIED,
					     16, 2, 4,
					     AudioSystem.NOT_SPECIFIED, true);
	DataLine.Info info = new DataLine.Info(Clip.class, format);
	return (Clip) AudioSystem.getLine(info);
    
public static javax.sound.sampled.ClipgetClip(javax.sound.sampled.Mixer$Info mixerInfo)
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 open(AudioFormat) or open(AudioInputStream) method.

This is a high-level method that uses getMixer and getLine internally.

param
mixerInfo a Mixer.Info object representing the desired mixer, or null for the system default mixer
return
a clip object from the specified mixer
throws
LineUnavailableException if a clip is not available from this mixer due to resource restrictions
throws
SecurityException if a clip is not available from this mixer due to security restrictions
throws
IllegalArgumentException if the system does not support at least one clip through the specified mixer
see
#getClip()
since
1.5

	AudioFormat format = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,
					     AudioSystem.NOT_SPECIFIED,
					     16, 2, 4,
					     AudioSystem.NOT_SPECIFIED, true);
	DataLine.Info info = new DataLine.Info(Clip.class, format);
	Mixer mixer = AudioSystem.getMixer(mixerInfo);
	return (Clip) mixer.getLine(info);
    
private static javax.sound.sampled.MixergetDefaultMixer(java.util.List providers, javax.sound.sampled.Line$Info info)
Attempts to locate and return a default Mixer that provides lines of the specified type.

param
providers the installed mixer providers
param
info The requested line type TargetDataLine.class, Clip.class or Port.class.
return
a Mixer that matches the requirements, or null if no default mixer found

	Class lineClass = info.getLineClass();
	String providerClassName = JDK13Services.getDefaultProviderClassName(lineClass);
	String instanceName = JDK13Services.getDefaultInstanceName(lineClass);
	Mixer mixer;

	if (providerClassName != null) {
	    MixerProvider defaultProvider = getNamedProvider(providerClassName, providers);
	    if (defaultProvider != null) {
		if (instanceName != null) {
		    mixer = getNamedMixer(instanceName, defaultProvider, info);
		    if (mixer != null) {
			return mixer;
		    }
		} else {
		    mixer = getFirstMixer(defaultProvider, info,
					  false /* mixing not required*/);
		    if (mixer != null) {
			return mixer;
		    }
		}

	    }
	}

	/* Provider class not specified or
	   provider class cannot be found, or
	   provider class and instance specified and instance cannot be found or is not appropriate */
	if (instanceName != null) {
	    mixer = getNamedMixer(instanceName, providers, info);
	    if (mixer != null) {
		return mixer;
	    }
	}


	/* No default are specified, or if something is specified, everything
	   failed. */
	return null;
    
private static javax.sound.sampled.MixergetFirstMixer(javax.sound.sampled.spi.MixerProvider provider, javax.sound.sampled.Line$Info info, boolean isMixingRequired)
From a given MixerProvider, return the first appropriate Mixer.

param
provider The MixerProvider to check for Mixers.
param
info The type of line the returned Mixer is required to support.
param
isMixingRequired If true, only Mixers that support mixing are returned for line types of SourceDataLine and Clip.
return
A Mixer that is considered appropriate, or null if none is found.

	Mixer.Info[] infos = provider.getMixerInfo();
	for (int j = 0; j < infos.length; j++) {
	    Mixer mixer = provider.getMixer(infos[j]);
	    if (isAppropriateMixer(mixer, info, isMixingRequired)) {
		return mixer;
	    }
	}
	return null;
    
private static java.util.ListgetFormatConversionProviders()
Obtains the set of format converters (codecs, transcoders, etc.) that are currently installed on the system.

return
an array of {@link javax.sound.sampled.spi.FormatConversionProvider FormatConversionProvider} objects representing the available format converters. If no format converters readers are available on the system, an array of length 0 is returned.

	return getProviders(FormatConversionProvider.class);
    
public static javax.sound.sampled.LinegetLine(javax.sound.sampled.Line$Info info)
Obtains a line that matches the description in the specified Line.Info object.

If a DataLine is requested, and info is an instance of DataLine.Info specifying at least one fully qualified audio format, the last one will be used as the default format of the returned DataLine.

If system properties javax.sound.sampled.Clip, javax.sound.sampled.Port, javax.sound.sampled.SourceDataLine and javax.sound.sampled.TargetDataLine are defined or they are defined in the file "sound.properties", they are used to retrieve default lines. For details, refer to the {@link AudioSystem class description}. If the respective property is not set, or the mixer requested in the property is not installed or does not provide the requested line, all installed mixers are queried for the requested line type. A Line will be returned from the first mixer providing the requested line type.

param
info a Line.Info object describing the desired kind of line
return
a line of the requested kind
throws
LineUnavailableException if a matching line is not available due to resource restrictions
throws
SecurityException if a matching line is not available due to security restrictions
throws
IllegalArgumentException if the system does not support at least one line matching the specified Line.Info object through any installed mixer

	LineUnavailableException lue = null;
	List providers = getMixerProviders();


	// 1: try from default mixer for this line class
	try {
	    Mixer mixer = getDefaultMixer(providers, info);
	    if (mixer != null && mixer.isLineSupported(info)) {
		return mixer.getLine(info);
	    }
	} catch (LineUnavailableException e) {
	    lue = e;
	} catch (IllegalArgumentException iae) {
	    // must not happen... but better to catch it here,
	    // if plug-ins are badly written
	}


	// 2: if that doesn't work, try to find any mixing mixer
	for(int i = 0; i < providers.size(); i++) {
	    MixerProvider provider = (MixerProvider) providers.get(i);
	    Mixer.Info[] infos = provider.getMixerInfo();

	    for (int j = 0; j < infos.length; j++) {
 		try {
		    Mixer mixer = provider.getMixer(infos[j]);
		    // see if this is an appropriate mixer which can mix
		    if (isAppropriateMixer(mixer, info, true)) {
			return mixer.getLine(info);
		    }
		} catch (LineUnavailableException e) {
		    lue = e;
		} catch (IllegalArgumentException iae) {
		    // must not happen... but better to catch it here,
		    // if plug-ins are badly written
		}
	    }
	}


	// 3: if that didn't work, try to find any non-mixing mixer
	for(int i = 0; i < providers.size(); i++) {
	    MixerProvider provider = (MixerProvider) providers.get(i);
	    Mixer.Info[] infos = provider.getMixerInfo();
	    for (int j = 0; j < infos.length; j++) {
 		try {
		    Mixer mixer = provider.getMixer(infos[j]);
		    // see if this is an appropriate mixer which can mix
		    if (isAppropriateMixer(mixer, info, false)) {
			return mixer.getLine(info);
		    }
		} catch (LineUnavailableException e) {
		    lue = e;
		} catch (IllegalArgumentException iae) {
		    // must not happen... but better to catch it here,
		    // if plug-ins are badly written
		}
	    }
	}

	// if this line was supported but was not available, throw the last
	// LineUnavailableException we got (??).
	if (lue != null) {
	    throw lue;
	}

	// otherwise, the requested line was not supported, so throw
	// an Illegal argument exception
	throw new IllegalArgumentException("No line matching " +
					   info.toString() + " is supported.");
    
public static javax.sound.sampled.MixergetMixer(javax.sound.sampled.Mixer$Info info)
Obtains the requested audio mixer.

param
info a Mixer.Info object representing the desired mixer, or null for the system default mixer
return
the requested mixer
throws
SecurityException if the requested mixer is unavailable because of security restrictions
throws
IllegalArgumentException if the info object does not represent a mixer installed on the system
see
#getMixerInfo


	Mixer mixer = null;
	List providers = getMixerProviders();

	for(int i = 0; i < providers.size(); i++ ) {

	    try {
		return ((MixerProvider)providers.get(i)).getMixer(info);

	    } catch (IllegalArgumentException e) {
	    } catch (NullPointerException e) {
		// $$jb 08.20.99:  If the strings in the info object aren't
		// set, then Netscape (using jdk1.1.5) tends to throw
		// NPE's when doing some string manipulation.  This is
		// probably not the best fix, but is solves the problem
		// of the NPE in Netscape using local classes
		// $$jb 11.01.99: Replacing this patch.
	    }
	}

	//$$fb if looking for default mixer, and not found yet, add a round of looking
	if (info == null) {
	    for(int i = 0; i < providers.size(); i++ ) {
		try {
		    MixerProvider provider = (MixerProvider) providers.get(i);
		    Mixer.Info[] infos = provider.getMixerInfo();
		    // start from 0 to last device (do not reverse this order)
		    for (int ii = 0; ii < infos.length; ii++) {
			try {
			    return provider.getMixer(infos[ii]);
			} catch (IllegalArgumentException e) {
			    // this is not a good default device :)
			}
		    }
		} catch (IllegalArgumentException e) {
		} catch (NullPointerException e) {
		}
	    }
	}


	throw new IllegalArgumentException("Mixer not supported: "
					   + (info!=null?info.toString():"null"));
    
public static javax.sound.sampled.Mixer$Info[]getMixerInfo()
Obtains an array of mixer info objects that represents the set of audio mixers that are currently installed on the system.

return
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.
see
#getMixer


	List infos = getMixerInfoList();
	Mixer.Info[] allInfos = (Mixer.Info[]) infos.toArray(new Mixer.Info[infos.size()]);
	return allInfos;
    
private static java.util.ListgetMixerInfoList()
Like getMixerInfo, but return List

	List providers = getMixerProviders();
	return getMixerInfoList(providers);
    
private static java.util.ListgetMixerInfoList(java.util.List providers)
Like getMixerInfo, but return List

	List infos = new ArrayList();

	Mixer.Info[] someInfos;	// per-mixer
	Mixer.Info[] allInfos;	// for all mixers

	for(int i = 0; i < providers.size(); i++ ) {
	    someInfos = (Mixer.Info[])
		((MixerProvider)providers.get(i)).getMixerInfo();

	    for (int j = 0; j < someInfos.length; j++) {
		infos.add(someInfos[j]);
	    }
	}

	return infos;
    
private static java.util.ListgetMixerProviders()
Obtains the set of MixerProviders on the system.

	return getProviders(MixerProvider.class);
    
private static javax.sound.sampled.MixergetNamedMixer(java.lang.String mixerName, javax.sound.sampled.spi.MixerProvider provider, javax.sound.sampled.Line$Info info)
Return a Mixer with a given name from a given MixerProvider. This method never requires the returned Mixer to do mixing.

param
mixerName The name of the Mixer to be returned.
param
provider The MixerProvider to check for Mixers.
param
info The type of line the returned Mixer is required to support.
return
A Mixer matching the requirements, or null if none is found.

	Mixer.Info[] infos = provider.getMixerInfo();
	for (int i = 0; i < infos.length; i++) {
	    if (infos[i].getName().equals(mixerName)) {
		Mixer mixer = provider.getMixer(infos[i]);
		if (isAppropriateMixer(mixer, info, false)) {
		    return mixer;
		}
	    }
	}
	return null;
    
private static javax.sound.sampled.MixergetNamedMixer(java.lang.String mixerName, java.util.List providers, javax.sound.sampled.Line$Info info)
From a List of MixerProviders, return a Mixer with a given name. This method never requires the returned Mixer to do mixing.

param
mixerName The name of the Mixer to be returned.
param
providers The List of MixerProviders to check for Mixers.
param
info The type of line the returned Mixer is required to support.
return
A Mixer matching the requirements, or null if none is found.

	for(int i = 0; i < providers.size(); i++) {
	    MixerProvider provider = (MixerProvider) providers.get(i);
	    Mixer mixer = getNamedMixer(mixerName, provider, info);
	    if (mixer != null) {
		return mixer;
	    }
	}
	return null;
    
private static javax.sound.sampled.spi.MixerProvidergetNamedProvider(java.lang.String providerClassName, java.util.List providers)
Return a MixerProvider of a given class from the list of MixerProviders. This method never requires the returned Mixer to do mixing.

param
providerClassName The class name of the provider to be returned.
param
providers The list of MixerProviders that is searched.
return
A MixerProvider of the requested class, or null if none is found.

	for(int i = 0; i < providers.size(); i++) {
	    MixerProvider provider = (MixerProvider) providers.get(i);
	    if (provider.getClass().getName().equals(providerClassName)) {
		return provider;
	    }
	}
	return null;
    
private static java.util.ListgetProviders(java.lang.Class providerClass)
Obtains the set of services currently installed on the system using sun.misc.Service, the SPI mechanism in 1.3.

return
a List of instances of providers for the requested service. If no providers are available, a vector of length 0 will be returned.

	return JDK13Services.getProviders(providerClass);
    
public static javax.sound.sampled.SourceDataLinegetSourceDataLine(javax.sound.sampled.AudioFormat format)
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 open(AudioFormat) or open(AudioFormat, int) method.

This is a high-level method that uses getMixer and getLine internally.

The returned SourceDataLine's default audio format will be initialized with format.

If the system property javax.sound.sampled.SourceDataLine is defined or it is defined in the file "sound.properties", it is used to retrieve the default source data line. For details, refer to the {@link AudioSystem class description}.

param
format an AudioFormat object specifying the supported audio format of the returned line, or null for any audio format
return
the desired SourceDataLine object
throws
LineUnavailableException if a matching source data line is not available due to resource restrictions
throws
SecurityException if a matching source data line is not available due to security restrictions
throws
IllegalArgumentException if the system does not support at least one source data line supporting the specified audio format through any installed mixer
see
#getSourceDataLine(AudioFormat, Mixer.Info)
since
1.5

	DataLine.Info info = new DataLine.Info(SourceDataLine.class, format);
	return (SourceDataLine) AudioSystem.getLine(info);
    
public static javax.sound.sampled.SourceDataLinegetSourceDataLine(javax.sound.sampled.AudioFormat format, javax.sound.sampled.Mixer$Info mixerinfo)
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 open(AudioFormat) or open(AudioFormat, int) method.

This is a high-level method that uses getMixer and getLine internally.

The returned SourceDataLine's default audio format will be initialized with format.

param
format an AudioFormat object specifying the supported audio format of the returned line, or null for any audio format
param
mixerinfo a Mixer.Info object representing the desired mixer, or null for the system default mixer
return
the desired SourceDataLine object
throws
LineUnavailableException if a matching source data line is not available from the specified mixer due to resource restrictions
throws
SecurityException if a matching source data line is not available from the specified mixer due to security restrictions
throws
IllegalArgumentException if the specified mixer does not support at least one source data line supporting the specified audio format
see
#getSourceDataLine(AudioFormat)
since
1.5

	DataLine.Info info = new DataLine.Info(SourceDataLine.class, format);
	Mixer mixer = AudioSystem.getMixer(mixerinfo);
	return (SourceDataLine) mixer.getLine(info);
  
public static javax.sound.sampled.Line$Info[]getSourceLineInfo(javax.sound.sampled.Line$Info info)
Obtains information about all source lines of a particular type that are supported by the installed mixers.

param
info a Line.Info object that specifies the kind of lines about which information is requested
return
an array of Line.Info objects describing source lines matching the type requested. If no matching source lines are supported, an array of length 0 is returned.
see
Mixer#getSourceLineInfo(Line.Info)


	Vector vector = new Vector();
	Line.Info[] currentInfoArray;

	Mixer mixer;
	Line.Info fullInfo = null;
	Mixer.Info[] infoArray = getMixerInfo();

	for (int i = 0; i < infoArray.length; i++) {

	    mixer = getMixer(infoArray[i]);

	    currentInfoArray = mixer.getSourceLineInfo(info);
	    for (int j = 0; j < currentInfoArray.length; j++) {
		vector.addElement(currentInfoArray[j]);
	    }
	}

	Line.Info[] returnedArray = new Line.Info[vector.size()];

	for (int i = 0; i < returnedArray.length; i++) {
	    returnedArray[i] = (Line.Info)vector.get(i);
	}

	return returnedArray;
    
public static javax.sound.sampled.TargetDataLinegetTargetDataLine(javax.sound.sampled.AudioFormat format)
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 open(AudioFormat) or open(AudioFormat, int) method.

This is a high-level method that uses getMixer and getLine internally.

The returned TargetDataLine's default audio format will be initialized with format.

param
format an AudioFormat object specifying the supported audio format of the returned line, or null for any audio format
return
the desired TargetDataLine object
throws
LineUnavailableException if a matching target data line is not available due to resource restrictions
throws
SecurityException if a matching target data line is not available due to security restrictions
throws
IllegalArgumentException if the system does not support at least one target data line supporting the specified audio format through any installed mixer
see
#getTargetDataLine(AudioFormat, Mixer.Info)
see
AudioPermission
since
1.5


	DataLine.Info info = new DataLine.Info(TargetDataLine.class, format);
	return (TargetDataLine) AudioSystem.getLine(info);
    
public static javax.sound.sampled.TargetDataLinegetTargetDataLine(javax.sound.sampled.AudioFormat format, javax.sound.sampled.Mixer$Info mixerinfo)
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 open(AudioFormat) or open(AudioFormat, int) method.

This is a high-level method that uses getMixer and getLine internally.

The returned TargetDataLine's default audio format will be initialized with format.

If the system property javax.sound.sampled.TargetDataLine is defined or it is defined in the file "sound.properties", it is used to retrieve the default target data line. For details, refer to the {@link AudioSystem class description}.

param
format an AudioFormat object specifying the supported audio format of the returned line, or null for any audio format
param
mixerinfo a Mixer.Info object representing the desired mixer, or null for the system default mixer
return
the desired TargetDataLine object
throws
LineUnavailableException if a matching target data line is not available from the specified mixer due to resource restrictions
throws
SecurityException if a matching target data line is not available from the specified mixer due to security restrictions
throws
IllegalArgumentException if the specified mixer does not support at least one target data line supporting the specified audio format
see
#getTargetDataLine(AudioFormat)
see
AudioPermission
since
1.5


	DataLine.Info info = new DataLine.Info(TargetDataLine.class, format);
	Mixer mixer = AudioSystem.getMixer(mixerinfo);
	return (TargetDataLine) mixer.getLine(info);
    
public static javax.sound.sampled.AudioFormat$Encoding[]getTargetEncodings(javax.sound.sampled.AudioFormat$Encoding sourceEncoding)
Obtains the encodings that the system can obtain from an audio input stream with the specified encoding using the set of installed format converters.

param
sourceEncoding the encoding for which conversion support is queried
return
array of encodings. If sourceEncodingis not supported, an array of length 0 is returned. Otherwise, the array will have a length of at least 1, representing sourceEncoding (no conversion).


	List codecs = getFormatConversionProviders();
	Vector encodings = new Vector();

	AudioFormat.Encoding encs[] = null;

	// gather from all the codecs
	for(int i=0; i<codecs.size(); i++ ) {
	    FormatConversionProvider codec = (FormatConversionProvider) codecs.get(i);
	    if( codec.isSourceEncodingSupported( sourceEncoding ) ) {
		encs = codec.getTargetEncodings();
		for (int j = 0; j < encs.length; j++) {
		    encodings.addElement( encs[j] );
		}
	    }
	}
	AudioFormat.Encoding encs2[] = (AudioFormat.Encoding[]) encodings.toArray(new AudioFormat.Encoding[0]);
	return encs2;
    
public static javax.sound.sampled.AudioFormat$Encoding[]getTargetEncodings(javax.sound.sampled.AudioFormat 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.

param
sourceFormat the audio format for which conversion is queried
return
array of encodings. If sourceFormatis 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).



	List codecs = getFormatConversionProviders();
	Vector encodings = new Vector();

	int size = 0;
	int index = 0;
	AudioFormat.Encoding encs[] = null;

	// gather from all the codecs

	for(int i=0; i<codecs.size(); i++ ) {
	    encs = ((FormatConversionProvider) codecs.get(i)).getTargetEncodings(sourceFormat);
	    size += encs.length;
	    encodings.addElement( encs );
	}

	// now build a new array

	AudioFormat.Encoding encs2[] = new AudioFormat.Encoding[size];
	for(int i=0; i<encodings.size(); i++ ) {
	    encs = (AudioFormat.Encoding [])(encodings.get(i));
	    for(int j=0; j<encs.length; j++ ) {
		encs2[index++] = encs[j];
	    }
	}
	return encs2;
    
public static javax.sound.sampled.AudioFormat[]getTargetFormats(javax.sound.sampled.AudioFormat$Encoding targetEncoding, javax.sound.sampled.AudioFormat 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.

param
targetEncoding the desired encoding after conversion
param
sourceFormat the audio format before conversion
return
array of formats. If no formats of the specified encoding are supported, an array of length 0 is returned.


	List codecs = getFormatConversionProviders();
	Vector formats = new Vector();

	int size = 0;
	int index = 0;
	AudioFormat fmts[] = null;

	// gather from all the codecs

	for(int i=0; i<codecs.size(); i++ ) {
	    FormatConversionProvider codec = (FormatConversionProvider) codecs.get(i);
	    fmts = codec.getTargetFormats(targetEncoding, sourceFormat);
	    size += fmts.length;
	    formats.addElement( fmts );
	}

	// now build a new array

	AudioFormat fmts2[] = new AudioFormat[size];
	for(int i=0; i<formats.size(); i++ ) {
	    fmts = (AudioFormat [])(formats.get(i));
	    for(int j=0; j<fmts.length; j++ ) {
		fmts2[index++] = fmts[j];
	    }
	}
	return fmts2;
    
public static javax.sound.sampled.Line$Info[]getTargetLineInfo(javax.sound.sampled.Line$Info info)
Obtains information about all target lines of a particular type that are supported by the installed mixers.

param
info a Line.Info object that specifies the kind of lines about which information is requested
return
an array of Line.Info objects describing target lines matching the type requested. If no matching target lines are supported, an array of length 0 is returned.
see
Mixer#getTargetLineInfo(Line.Info)


	Vector vector = new Vector();
	Line.Info[] currentInfoArray;

	Mixer mixer;
	Line.Info fullInfo = null;
	Mixer.Info[] infoArray = getMixerInfo();

	for (int i = 0; i < infoArray.length; i++) {

	    mixer = getMixer(infoArray[i]);

	    currentInfoArray = mixer.getTargetLineInfo(info);
	    for (int j = 0; j < currentInfoArray.length; j++) {
		vector.addElement(currentInfoArray[j]);
	    }
	}

	Line.Info[] returnedArray = new Line.Info[vector.size()];

	for (int i = 0; i < returnedArray.length; i++) {
	    returnedArray[i] = (Line.Info)vector.get(i);
	}

	return returnedArray;
    
private static booleanisAppropriateMixer(javax.sound.sampled.Mixer mixer, javax.sound.sampled.Line$Info lineInfo, boolean isMixingRequired)
Checks if a Mixer is appropriate. A Mixer is considered appropriate if it support the given line type. If isMixingRequired is true and the line type is an output one (SourceDataLine, Clip), the mixer is appropriate if it supports at least 2 (concurrent) lines of the given type.

return
true if the mixer is considered appropriate according to the rules given above, false otherwise.

	if (! mixer.isLineSupported(lineInfo)) {
	    return false;
	}
	Class lineClass = lineInfo.getLineClass();
	if (isMixingRequired 
	    && (SourceDataLine.class.isAssignableFrom(lineClass) ||
		Clip.class.isAssignableFrom(lineClass))) {
	    int maxLines = mixer.getMaxLines(lineInfo);
	    return ((maxLines == NOT_SPECIFIED) || (maxLines > 1));
	}
	return true;
    
public static booleanisConversionSupported(javax.sound.sampled.AudioFormat$Encoding targetEncoding, javax.sound.sampled.AudioFormat sourceFormat)
Indicates whether an audio input stream of the specified encoding can be obtained from an audio input stream that has the specified format.

param
targetEncoding the desired encoding after conversion
param
sourceFormat the audio format before conversion
return
true if the conversion is supported, otherwise false



	List codecs = getFormatConversionProviders();

	for(int i=0; i<codecs.size(); i++ ) {
	    FormatConversionProvider codec = (FormatConversionProvider) codecs.get(i);
	    if(codec.isConversionSupported(targetEncoding,sourceFormat) ) {
		return true;
	    }
	}
	return false;
    
public static booleanisConversionSupported(javax.sound.sampled.AudioFormat targetFormat, javax.sound.sampled.AudioFormat sourceFormat)
Indicates whether an audio input stream of a specified format can be obtained from an audio input stream of another specified format.

param
targetFormat the desired audio format after conversion
param
sourceFormat the audio format before conversion
return
true if the conversion is supported, otherwise false


	List codecs = getFormatConversionProviders();

	for(int i=0; i<codecs.size(); i++ ) {
	    FormatConversionProvider codec = (FormatConversionProvider) codecs.get(i);
	    if(codec.isConversionSupported(targetFormat, sourceFormat) ) {
		return true;
	    }
	}
	return false;
    
public static booleanisFileTypeSupported(javax.sound.sampled.AudioFileFormat$Type fileType)
Indicates whether file writing support for the specified file type is provided by the system.

param
fileType the file type for which write capabilities are queried
return
true if the file type is supported, otherwise false


	List providers = getAudioFileWriters();

	for(int i=0; i < providers.size(); i++) {
	    AudioFileWriter writer = (AudioFileWriter) providers.get(i);
	    if (writer.isFileTypeSupported(fileType)) {
		return true;
	    }
	}
	return false;
    
public static booleanisFileTypeSupported(javax.sound.sampled.AudioFileFormat$Type fileType, javax.sound.sampled.AudioInputStream stream)
Indicates whether an audio file of the specified file type can be written from the indicated audio input stream.

param
fileType the file type for which write capabilities are queried
param
stream the stream for which file-writing support is queried
return
true if the file type is supported for this audio input stream, otherwise false


	List providers = getAudioFileWriters();

	for(int i=0; i < providers.size(); i++) {
	    AudioFileWriter writer = (AudioFileWriter) providers.get(i);
	    if(writer.isFileTypeSupported(fileType, stream)) {
		return true;
	    }
	}
	return false;
    
public static booleanisLineSupported(javax.sound.sampled.Line$Info info)
Indicates whether the system supports any lines that match the specified Line.Info object. A line is supported if any installed mixer supports it.

param
info a Line.Info object describing the line for which support is queried
return
true if at least one matching line is supported, otherwise false
see
Mixer#isLineSupported(Line.Info)


	Mixer mixer;
	Mixer.Info[] infoArray = getMixerInfo();

	for (int i = 0; i < infoArray.length; i++) {

	    if( infoArray[i] != null ) {
		mixer = getMixer(infoArray[i]);
		if (mixer.isLineSupported(info)) {
		    return true;
		}
	    }
	}

	return false;
    
public static intwrite(javax.sound.sampled.AudioInputStream stream, javax.sound.sampled.AudioFileFormat$Type fileType, java.io.OutputStream out)
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.

param
stream the audio input stream containing audio data to be written to the file
param
fileType the kind of audio file to write
param
out the stream to which the file data should be written
return
the number of bytes written to the output stream
throws
IOException if an input/output exception occurs
throws
IllegalArgumentException if the file type is not supported by the system
see
#isFileTypeSupported
see
#getAudioFileTypes


	List providers = getAudioFileWriters();
	int bytesWritten = 0;
	boolean flag = false;

	for(int i=0; i < providers.size(); i++) {
	    AudioFileWriter writer = (AudioFileWriter) providers.get(i);
	    try {
		bytesWritten = writer.write( stream, fileType, out ); // throws IOException
		flag = true;
		break;
	    } catch (IllegalArgumentException e) {
		// thrown if this provider cannot write the sequence, try the next
		continue;
	    }
	}
	if(!flag) {
	    throw new IllegalArgumentException("could not write audio file: file type not supported: " + fileType);
	} else {
	    return bytesWritten;
	}
    
public static intwrite(javax.sound.sampled.AudioInputStream stream, javax.sound.sampled.AudioFileFormat$Type fileType, java.io.File out)
Writes a stream of bytes representing an audio file of the specified file type to the external file provided.

param
stream the audio input stream containing audio data to be written to the file
param
fileType the kind of audio file to write
param
out the external file to which the file data should be written
return
the number of bytes written to the file
throws
IOException if an I/O exception occurs
throws
IllegalArgumentException if the file type is not supported by the system
see
#isFileTypeSupported
see
#getAudioFileTypes


	List providers = getAudioFileWriters();
	int bytesWritten = 0;
	boolean flag = false;

	for(int i=0; i < providers.size(); i++) {
	    AudioFileWriter writer = (AudioFileWriter) providers.get(i);
	    try {
		bytesWritten = writer.write( stream, fileType, out ); // throws IOException
		flag = true;
		break;
	    } catch (IllegalArgumentException e) {
		// thrown if this provider cannot write the sequence, try the next
		continue;
	    }
	}
	if (!flag) {
	    throw new IllegalArgumentException("could not write audio file: file type not supported: " + fileType);
	} else {
	    return bytesWritten;
	}