FileDocCategorySizeDatePackage
AudioSystem.javaAPI DocAndroid 1.5 API26140Wed May 06 22:41:02 BST 2009javax.sound.sampled

AudioSystem

public class AudioSystem extends Object

Fields Summary
public static final int
NOT_SPECIFIED
private static final String
audioFileReaderPath
private static final String
audioFileWriterPath
private static final String
formatConversionProviderPath
private static final String
mixerProviderPath
private static final String
CLIP
private static final String
PORT
private static final String
SOURCEDATALINE
private static final String
TARGETDATALINE
Constructors Summary
Methods Summary
public static javax.sound.sampled.AudioFileFormatgetAudioFileFormat(java.io.InputStream stream)


        for (Iterator providers = ProviderService.getProviders(
                audioFileReaderPath).iterator(); providers.hasNext();) {
            try {
                return ((AudioFileReader) (providers.next()))
                        .getAudioFileFormat(stream);
            } catch (ClassCastException e) {} catch (UnsupportedAudioFileException e) {}
        }
        // sound.14=File is not a supported file type
        throw new UnsupportedAudioFileException(Messages.getString("sound.14")); //$NON-NLS-1$
    
public static javax.sound.sampled.AudioFileFormatgetAudioFileFormat(java.net.URL url)


        for (Iterator providers = ProviderService.getProviders(
                audioFileReaderPath).iterator(); providers.hasNext();) {
            try {
                return ((AudioFileReader) (providers.next()))
                        .getAudioFileFormat(url);
            } catch (ClassCastException e) {} catch (UnsupportedAudioFileException e) {}
        }
        // sound.14=File is not a supported file type
        throw new UnsupportedAudioFileException(Messages.getString("sound.14")); //$NON-NLS-1$
    
public static javax.sound.sampled.AudioFileFormatgetAudioFileFormat(java.io.File file)


        for (Iterator providers = ProviderService.getProviders(
                audioFileReaderPath).iterator(); providers.hasNext();) {
            try {
                return ((AudioFileReader) (providers.next()))
                        .getAudioFileFormat(file);
            } catch (ClassCastException e) {} catch (UnsupportedAudioFileException e) {}
        }
        // sound.14=File is not a supported file type
        throw new UnsupportedAudioFileException(Messages.getString("sound.14")); //$NON-NLS-1$
    
public static javax.sound.sampled.AudioFileFormat$Type[]getAudioFileTypes()

        List<AudioFileFormat.Type> result = new ArrayList<AudioFileFormat.Type>();
        for (Iterator providers = ProviderService.getProviders(
                audioFileWriterPath).iterator(); providers.hasNext();) {
            try {
                AudioFileFormat.Type[] types = ((AudioFileWriter) (providers
                        .next())).getAudioFileTypes();
                for (AudioFileFormat.Type type : types) {
                    result.add(type);
                }
            } catch (ClassCastException e) {}
        }
        AudioFileFormat.Type[] temp = new AudioFileFormat.Type[result.size()];
        return result.toArray(temp);
    
public static javax.sound.sampled.AudioFileFormat$Type[]getAudioFileTypes(javax.sound.sampled.AudioInputStream stream)

        List<AudioFileFormat.Type> result = new ArrayList<AudioFileFormat.Type>();
        for (Iterator providers = ProviderService.getProviders(
                audioFileWriterPath).iterator(); providers.hasNext();) {
            try {
                AudioFileFormat.Type[] types = ((AudioFileWriter) (providers
                        .next())).getAudioFileTypes(stream);
                for (AudioFileFormat.Type type : types) {
                    result.add(type);
                }
            } catch (ClassCastException e) {}
        }
        AudioFileFormat.Type[] temp = new AudioFileFormat.Type[result.size()];
        return result.toArray(temp);
    
public static javax.sound.sampled.AudioInputStreamgetAudioInputStream(javax.sound.sampled.AudioFormat$Encoding targetEncoding, javax.sound.sampled.AudioInputStream sourceStream)


        if (sourceStream.getFormat().getEncoding().equals(targetEncoding)) {
            return sourceStream;
        }
        for (Iterator providers = ProviderService.getProviders(
                formatConversionProviderPath).iterator(); providers.hasNext();) {
            try {
                return ((FormatConversionProvider) (providers.next()))
                        .getAudioInputStream(targetEncoding, sourceStream);
            } catch (ClassCastException e) {} catch (IllegalArgumentException e) {}
        }
        // sound.12=Could not get audio input stream from source stream
        throw new IllegalArgumentException(Messages.getString("sound.12")); //$NON-NLS-1$
    
public static javax.sound.sampled.AudioInputStreamgetAudioInputStream(javax.sound.sampled.AudioFormat targetFormat, javax.sound.sampled.AudioInputStream sourceStream)


        if (sourceStream.getFormat().matches(targetFormat)) {
            return sourceStream;
        }
        for (Iterator providers = ProviderService.getProviders(
                formatConversionProviderPath).iterator(); providers.hasNext();) {
            try {
                return ((FormatConversionProvider) (providers.next()))
                        .getAudioInputStream(targetFormat, sourceStream);
            } catch (ClassCastException e) {} catch (IllegalArgumentException e) {}
        }
        // sound.13=Could not get audio input stream from source stream
        throw new IllegalArgumentException(Messages.getString("sound.13")); //$NON-NLS-1$
    
public static javax.sound.sampled.AudioInputStreamgetAudioInputStream(java.io.InputStream stream)


        if (stream instanceof AudioInputStream) {
            return (AudioInputStream) stream;
        }
        for (Iterator providers = ProviderService.getProviders(
                audioFileReaderPath).iterator(); providers.hasNext();) {
            try {
                return ((AudioFileReader) (providers.next()))
                        .getAudioInputStream(stream);
            } catch (ClassCastException e) {} catch (UnsupportedAudioFileException e) {}
        }
        // BEGIN android-added
        try {
            AudioFileReader reader = (AudioFileReader)(Class.forName("com.android.internal.sound.sampled.AndroidAudioFileReader").newInstance());
            return reader.getAudioInputStream(stream);
        } catch (Exception ex) {
            // Ignore
        }
        // END android-added
        // sound.15=Could not get audio input stream from input stream
        throw new UnsupportedAudioFileException(Messages.getString("sound.15")); //$NON-NLS-1$
    
public static javax.sound.sampled.AudioInputStreamgetAudioInputStream(java.net.URL url)


        for (Iterator providers = ProviderService.getProviders(
                audioFileReaderPath).iterator(); providers.hasNext();) {
            try {
                return ((AudioFileReader) (providers.next()))
                        .getAudioInputStream(url);
            } catch (ClassCastException e) {} catch (UnsupportedAudioFileException e) {}
        }
        // BEGIN android-added
        try {
            AudioFileReader reader = (AudioFileReader)(Class.forName("com.android.internal.sound.sampled.AndroidAudioFileReader").newInstance());
            return reader.getAudioInputStream(url);
        } catch (Exception ex) {
            // Ignore
        }
        // END android-added
        // sound.16=Could not get audio input stream from input URL
        throw new UnsupportedAudioFileException(Messages.getString("sound.16")); //$NON-NLS-1$
    
public static javax.sound.sampled.AudioInputStreamgetAudioInputStream(java.io.File file)


        for (Iterator providers = ProviderService.getProviders(
                audioFileReaderPath).iterator(); providers.hasNext();) {
            try {
                return ((AudioFileReader) (providers.next()))
                        .getAudioInputStream(file);
            } catch (ClassCastException e) {} catch (UnsupportedAudioFileException e) {}
        }
        // BEGIN android-added
        try {
            AudioFileReader reader = (AudioFileReader)(Class.forName("com.android.internal.sound.sampled.AndroidAudioFileReader").newInstance());
            return reader.getAudioInputStream(file);
        } catch (Exception ex) {
            // Ignore
        }
        // END android-added
        // sound.17=Could not get audio input stream from input file
        throw new UnsupportedAudioFileException(Messages.getString("sound.17")); //$NON-NLS-1$
    
public static javax.sound.sampled.ClipgetClip(javax.sound.sampled.Mixer$Info mixerInfo)

        return (Clip) (getMixer(mixerInfo).getLine(new Line.Info(Clip.class)));
    
public static javax.sound.sampled.ClipgetClip()

        return (Clip) getLine(new Line.Info(Clip.class));
    
public static javax.sound.sampled.LinegetLine(javax.sound.sampled.Line$Info info)

        String propName = null;
        Class lineClass = info.getLineClass();

        if (Clip.class.isAssignableFrom(lineClass)) {
            propName = CLIP;
        } else if (Port.class.isAssignableFrom(lineClass)) {
            propName = PORT;
        } else if (SourceDataLine.class.isAssignableFrom(lineClass)) {
            propName = SOURCEDATALINE;
        } else if (TargetDataLine.class.isAssignableFrom(lineClass)) {
            propName = TARGETDATALINE;
        }
        return getLine(propName, info);
    
private static javax.sound.sampled.LinegetLine(java.lang.String propName, javax.sound.sampled.Line$Info info)


        List<?> mixerProviders = ProviderService
                .getProviders(mixerProviderPath);

        if (propName != null) {
            String propVal = System.getProperty(propName);
            if (propVal != null) {
                Mixer m = getMixer(propVal, info, mixerProviders);
                if (m != null) {
                    Line l = m.getLine(info);
                    if (l != null) {
                        return l;
                    }
                }
            }

            Properties soundProperties = ProviderService.getSoundProperties();
            propVal = soundProperties.getProperty(propName);
            if (propVal != null) {
                Mixer m = getMixer(propVal, info, mixerProviders);
                if (m != null) {
                    Line l = m.getLine(info);
                    if (l != null) {
                        return l;
                    }
                }
            }
        }

        for (Iterator providers = ProviderService.getProviders(
                mixerProviderPath).iterator(); providers.hasNext();) {
            try {
                MixerProvider pr = (MixerProvider) (providers.next());
                Mixer.Info[] mixinfos = pr.getMixerInfo();
                for (Mixer.Info mixinfo : mixinfos) {
                    try {
                        Mixer mix = pr.getMixer(mixinfo);
                        return mix.getLine(info);
                    } catch (IllegalArgumentException e) {
                        // continue
                    }
                }
            } catch (ClassCastException e) {}
        }
        
        // BEGIN android-added
        if (CLIP.equals(propName)) {
            try {
                return (Clip)(Class.forName("com.android.internal.sound.sampled.AndroidClip").newInstance());
            } catch (Exception ex) {
                // Ignore
            }
        }
        // END android-added
        
        // sound.11=Could not get line
        throw new IllegalArgumentException(Messages.getString("sound.11")); //$NON-NLS-1$
    
public static javax.sound.sampled.MixergetMixer(javax.sound.sampled.Mixer$Info info)

        Mixer.Info[] infos;
        Mixer.Info inf;
        if (info == null) {
            infos = getMixerInfo();
            if (infos == null) {
                throw new IllegalArgumentException(
                        "No system default mixer installed"); //$NON-NLS-1$
            }
            inf = infos[0];
        } else {
            inf = info;
        }

        for (Iterator providers = ProviderService.getProviders(
                mixerProviderPath).iterator(); providers.hasNext();) {
            try {
                return ((MixerProvider) (providers.next())).getMixer(inf);
            } catch (ClassCastException e) {} catch (IllegalArgumentException e) {}
        }
        throw new IllegalArgumentException("Mixer not supported: " + inf); //$NON-NLS-1$
    
private static javax.sound.sampled.MixergetMixer(java.lang.String propVal, javax.sound.sampled.Line$Info info, java.util.List mixerProviders)


        int index = propVal.indexOf("#"); //$NON-NLS-1$
        String className;
        String mixName;
        if (index == -1) {
            className = propVal.trim();
            mixName = ""; //$NON-NLS-1$
        } else {
            className = propVal.substring(0, index).trim();
            if (index == propVal.length()) {
                mixName = ""; //$NON-NLS-1$
            } else {
                mixName = propVal.substring(index + 1).trim();
            }
        }
        Mixer.Info[] minfos = null;
        if (!className.equals("")) { //$NON-NLS-1$
            for (Iterator providers = mixerProviders.iterator(); providers
                    .hasNext();) {
                try {
                    MixerProvider pr = (MixerProvider) (providers.next());
                    if (className.equals(pr.getClass().getName())) {
                        minfos = pr.getMixerInfo();
                        break;
                    }
                } catch (ClassCastException e) {}
            }
        }
        if (minfos == null) {
            minfos = getMixerInfo();
        }

        if (!mixName.equals("")) { //$NON-NLS-1$
            for (Mixer.Info minfo : minfos) {
                if (mixName.equals(minfo.getName())) {
                    return getMixer(minfo);
                }
            }
        }
        if (minfos.length > 0) {
            return getMixer(minfos[0]);
        }
        return null;
    
public static javax.sound.sampled.Mixer$Info[]getMixerInfo()

 //$NON-NLS-1$

        
        List<Mixer.Info> result = new ArrayList<Mixer.Info>();
        for (Iterator providers = ProviderService.getProviders(
                mixerProviderPath).iterator(); providers.hasNext();) {
            try {
                Mixer.Info[] infos = ((MixerProvider) (providers.next()))
                        .getMixerInfo();
                for (Mixer.Info info : infos) {
                    result.add(info);
                }
            } catch (ClassCastException e) {}
        }
        Mixer.Info[] temp = new Mixer.Info[result.size()];
        return result.toArray(temp);
    
public static javax.sound.sampled.SourceDataLinegetSourceDataLine(javax.sound.sampled.AudioFormat format)

        SourceDataLine line = (SourceDataLine) getLine(new Line.Info(
                SourceDataLine.class));
        line.open(format);
        return line;
    
public static javax.sound.sampled.SourceDataLinegetSourceDataLine(javax.sound.sampled.AudioFormat format, javax.sound.sampled.Mixer$Info mixerinfo)


        SourceDataLine line = (SourceDataLine) getMixer(mixerinfo).getLine(
                new Line.Info(SourceDataLine.class));
        line.open(format);
        return line;
    
public static javax.sound.sampled.Line$Info[]getSourceLineInfo(javax.sound.sampled.Line$Info info)

        List<Line.Info> result = new ArrayList<Line.Info>();
        for (Iterator providers = ProviderService.getProviders(
                mixerProviderPath).iterator(); providers.hasNext();) {
            try {
                MixerProvider pr = (MixerProvider) providers.next();
                Mixer.Info[] mixinfos = pr.getMixerInfo();
                for (Mixer.Info mixinfo : mixinfos) {
                    Mixer mix = pr.getMixer(mixinfo);
                    Line.Info[] linfos = mix.getSourceLineInfo(info);
                    for (Line.Info linfo : linfos) {
                        result.add(linfo);
                    }
                }
            } catch (ClassCastException e) {}
        }
        Line.Info[] temp = new Line.Info[result.size()];
        return result.toArray(temp);
    
public static javax.sound.sampled.TargetDataLinegetTargetDataLine(javax.sound.sampled.AudioFormat format)

        TargetDataLine line = (TargetDataLine) getLine(new Line.Info(
                TargetDataLine.class));
        line.open(format);
        return line;
    
public static javax.sound.sampled.TargetDataLinegetTargetDataLine(javax.sound.sampled.AudioFormat format, javax.sound.sampled.Mixer$Info mixerinfo)


        TargetDataLine line = (TargetDataLine) getMixer(mixerinfo).getLine(
                new Line.Info(TargetDataLine.class));
        line.open(format);
        return line;
    
public static javax.sound.sampled.AudioFormat$Encoding[]getTargetEncodings(javax.sound.sampled.AudioFormat$Encoding sourceEncoding)


        List<AudioFormat.Encoding> result = new ArrayList<AudioFormat.Encoding>();
        for (Iterator providers = ProviderService.getProviders(
                formatConversionProviderPath).iterator(); providers.hasNext();) {
            try {
                FormatConversionProvider pr = (FormatConversionProvider) providers
                        .next();
                if (!pr.isSourceEncodingSupported(sourceEncoding)) {
                    continue;
                }
                AudioFormat.Encoding[] encodings = pr.getTargetEncodings();
                for (AudioFormat.Encoding encoding : encodings) {
                    result.add(encoding);
                }
            } catch (ClassCastException e) {}
        }
        AudioFormat.Encoding[] temp = new AudioFormat.Encoding[result.size()];
        return result.toArray(temp);
    
public static javax.sound.sampled.AudioFormat$Encoding[]getTargetEncodings(javax.sound.sampled.AudioFormat sourceFormat)


        List<AudioFormat.Encoding> result = new ArrayList<AudioFormat.Encoding>();
        for (Iterator providers = ProviderService.getProviders(
                formatConversionProviderPath).iterator(); providers.hasNext();) {
            try {
                AudioFormat.Encoding[] encodings = ((FormatConversionProvider) (providers
                        .next())).getTargetEncodings(sourceFormat);
                for (AudioFormat.Encoding encoding : encodings) {
                    result.add(encoding);
                }
            } catch (ClassCastException e) {}
        }
        AudioFormat.Encoding[] temp = new AudioFormat.Encoding[result.size()];
        return result.toArray(temp);
    
public static javax.sound.sampled.AudioFormat[]getTargetFormats(javax.sound.sampled.AudioFormat$Encoding targetEncoding, javax.sound.sampled.AudioFormat sourceFormat)


        List<AudioFormat> result = new ArrayList<AudioFormat>();
        for (Iterator providers = ProviderService.getProviders(
                formatConversionProviderPath).iterator(); providers.hasNext();) {
            try {
                AudioFormat[] formats = ((FormatConversionProvider) (providers
                        .next()))
                        .getTargetFormats(targetEncoding, sourceFormat);
                for (AudioFormat format : formats) {
                    result.add(format);
                }
            } catch (ClassCastException e) {}
        }
        AudioFormat[] temp = new AudioFormat[result.size()];
        return result.toArray(temp);
    
public static javax.sound.sampled.Line$Info[]getTargetLineInfo(javax.sound.sampled.Line$Info info)

        List<Line.Info> result = new ArrayList<Line.Info>();
        for (Iterator providers = ProviderService.getProviders(
                mixerProviderPath).iterator(); providers.hasNext();) {
            try {
                MixerProvider pr = (MixerProvider) providers.next();
                Mixer.Info[] mixinfos = pr.getMixerInfo();
                for (Mixer.Info mixinfo : mixinfos) {
                    Mixer mix = pr.getMixer(mixinfo);
                    Line.Info[] linfos = mix.getTargetLineInfo(info);
                    for (Line.Info linfo : linfos) {
                        result.add(linfo);
                    }
                }
            } catch (ClassCastException e) {}
        }
        Line.Info[] temp = new Line.Info[result.size()];
        return result.toArray(temp);
    
public static booleanisConversionSupported(javax.sound.sampled.AudioFormat$Encoding targetEncoding, javax.sound.sampled.AudioFormat sourceFormat)


        for (Iterator providers = ProviderService.getProviders(
                formatConversionProviderPath).iterator(); providers.hasNext();) {
            if (((FormatConversionProvider) (providers.next()))
                    .isConversionSupported(targetEncoding, sourceFormat)) {
                return true;
            }
        }
        return false;
    
public static booleanisConversionSupported(javax.sound.sampled.AudioFormat targetFormat, javax.sound.sampled.AudioFormat sourceFormat)


        for (Iterator providers = ProviderService.getProviders(
                formatConversionProviderPath).iterator(); providers.hasNext();) {
            if (((FormatConversionProvider) (providers.next()))
                    .isConversionSupported(targetFormat, sourceFormat)) {
                return true;
            }
        }
        return false;
    
public static booleanisFileTypeSupported(javax.sound.sampled.AudioFileFormat$Type fileType)


        for (Iterator providers = ProviderService.getProviders(
                audioFileWriterPath).iterator(); providers.hasNext();) {
            if (((AudioFileWriter) (providers.next()))
                    .isFileTypeSupported(fileType)) {
                return true;
            }
        }
        return false;
    
public static booleanisFileTypeSupported(javax.sound.sampled.AudioFileFormat$Type fileType, javax.sound.sampled.AudioInputStream stream)


        for (Iterator providers = ProviderService.getProviders(
                audioFileWriterPath).iterator(); providers.hasNext();) {
            if (((AudioFileWriter) (providers.next())).isFileTypeSupported(
                    fileType, stream)) {
                return true;
            }
        }
        return false;
    
public static booleanisLineSupported(javax.sound.sampled.Line$Info info)


        for (Iterator providers = ProviderService.getProviders(
                mixerProviderPath).iterator(); providers.hasNext();) {
            try {
                MixerProvider pr = (MixerProvider) providers.next();
                Mixer.Info[] mixinfos = pr.getMixerInfo();
                for (Mixer.Info mixinfo : mixinfos) {
                    Mixer mix = pr.getMixer(mixinfo);
                    if (mix.isLineSupported(info)) {
                        return true;
                    }
                }
            } catch (ClassCastException e) {}
        }
        return false;
    
public static intwrite(javax.sound.sampled.AudioInputStream stream, javax.sound.sampled.AudioFileFormat$Type fileType, java.io.OutputStream out)

        AudioFileWriter writer;
        for (Iterator providers = ProviderService.getProviders(
                audioFileWriterPath).iterator(); providers.hasNext();) {
            writer = (AudioFileWriter) (providers.next());
            if (writer.isFileTypeSupported(fileType, stream)) {
                return writer.write(stream, fileType, out);
            }
        }
        // sound.18=Type is not supported
        throw new IllegalArgumentException(Messages.getString("sound.18")); //$NON-NLS-1$
    
public static intwrite(javax.sound.sampled.AudioInputStream stream, javax.sound.sampled.AudioFileFormat$Type fileType, java.io.File out)

        AudioFileWriter writer;
        for (Iterator providers = ProviderService.getProviders(
                audioFileWriterPath).iterator(); providers.hasNext();) {
            writer = (AudioFileWriter) (providers.next());
            if (writer.isFileTypeSupported(fileType, stream)) {
                return writer.write(stream, fileType, out);
            }
        }
        // sound.18=Type is not supported
        throw new IllegalArgumentException(Messages.getString("sound.18")); //$NON-NLS-1$