Method from javax.sound.sampled.AudioSystem Detail: |
public static AudioFileFormat getAudioFileFormat(InputStream stream) throws UnsupportedAudioFileException, IOException {
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;
}
}
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 {
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;
}
}
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 {
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;
}
}
Obtains the audio file format of the specified File . The File must
point to valid audio file data. |
public static Type[] getAudioFileTypes() {
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;
}
Obtains the file types for which file writing support is provided by the system. |
public static Type[] getAudioFileTypes(AudioInputStream stream) {
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;
}
Obtains the file types that the system can write from the
audio input stream specified. |
public static AudioInputStream getAudioInputStream(InputStream stream) throws UnsupportedAudioFileException, IOException {
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;
}
}
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 {
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;
}
}
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 {
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;
}
}
Obtains an audio input stream from the provided File . The File must
point to valid audio file data. |
public static AudioInputStream getAudioInputStream(Encoding targetEncoding,
AudioInputStream sourceStream) {
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());
}
Obtains an audio input stream of the indicated encoding, by converting the
provided audio input stream. |
public static AudioInputStream getAudioInputStream(AudioFormat targetFormat,
AudioInputStream sourceStream) {
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());
}
Obtains an audio input stream of the indicated format, by converting the
provided audio input stream. |
public static Clip getClip() throws LineUnavailableException {
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);
}
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 class description . |
public static Clip getClip(Info mixerInfo) throws LineUnavailableException {
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);
}
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. |
public static Line getLine(Info info) throws LineUnavailableException {
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.");
}
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 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. |
public static Mixer getMixer(Info info) {
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"));
}
Obtains the requested audio mixer. |
public static Info[] getMixerInfo() {
List infos = getMixerInfoList();
Mixer.Info[] allInfos = (Mixer.Info[]) infos.toArray(new Mixer.Info[infos.size()]);
return allInfos;
}
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 {
DataLine.Info info = new DataLine.Info(SourceDataLine.class, format);
return (SourceDataLine) AudioSystem.getLine(info);
}
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 class description . |
public static SourceDataLine getSourceDataLine(AudioFormat format,
Info mixerinfo) throws LineUnavailableException {
DataLine.Info info = new DataLine.Info(SourceDataLine.class, format);
Mixer mixer = AudioSystem.getMixer(mixerinfo);
return (SourceDataLine) mixer.getLine(info);
}
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 . |
public static Info[] getSourceLineInfo(Info 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;
}
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 {
DataLine.Info info = new DataLine.Info(TargetDataLine.class, format);
return (TargetDataLine) AudioSystem.getLine(info);
}
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 .
If the system property
{@code 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 class description . |
public static TargetDataLine getTargetDataLine(AudioFormat format,
Info mixerinfo) throws LineUnavailableException {
DataLine.Info info = new DataLine.Info(TargetDataLine.class, format);
Mixer mixer = AudioSystem.getMixer(mixerinfo);
return (TargetDataLine) mixer.getLine(info);
}
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 . |
public static Encoding[] getTargetEncodings(Encoding sourceEncoding) {
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;
}
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 Encoding[] getTargetEncodings(AudioFormat sourceFormat) {
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;
}
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(Encoding targetEncoding,
AudioFormat sourceFormat) {
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;
}
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 Info[] getTargetLineInfo(Info 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;
}
Obtains information about all target lines of a particular type that are supported
by the installed mixers. |
public static boolean isConversionSupported(Encoding targetEncoding,
AudioFormat sourceFormat) {
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;
}
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) {
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;
}
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(Type fileType) {
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;
}
Indicates whether file writing support for the specified file type is provided
by the system. |
public static boolean isFileTypeSupported(Type fileType,
AudioInputStream stream) {
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;
}
Indicates whether an audio file of the specified file type can be written
from the indicated audio input stream. |
public static boolean isLineSupported(Info 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;
}
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 int write(AudioInputStream stream,
Type fileType,
OutputStream out) throws IOException {
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;
}
}
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,
Type fileType,
File out) throws IOException {
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;
}
}
Writes a stream of bytes representing an audio file of the specified file type
to the external file provided. |