⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 audiosystem.java

📁 gcc的组建
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* Main interface to audio system   Copyright (C) 2005 Free Software Foundation, Inc.This file is part of GNU Classpath.GNU Classpath is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.GNU Classpath is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING.  If not, write to theFree Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA02110-1301 USA.Linking this library statically or dynamically with other modules ismaking a combined work based on this library.  Thus, the terms andconditions of the GNU General Public License cover the wholecombination.As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule.  An independent module is a module which is not derived fromor based on this library.  If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so.  If you do not wish to do so, delete thisexception statement from your version. */package javax.sound.sampled;import gnu.classpath.ServiceFactory;import java.io.File;import java.io.IOException;import java.io.InputStream;import java.io.OutputStream;import java.net.URL;import java.util.HashSet;import java.util.Iterator;import javax.sound.sampled.spi.AudioFileReader;import javax.sound.sampled.spi.AudioFileWriter;import javax.sound.sampled.spi.FormatConversionProvider;import javax.sound.sampled.spi.MixerProvider;/** * This clas is the primary interface to the audio system.  It contains * a number of static methods which can be used to access this package's * functionality. *  * @since 1.3 */public class AudioSystem{  /**   * A constant which can be passed to a number of methods in this package,   * to indicate an unspecified value.   */  public static final int NOT_SPECIFIED = -1;  /**   * Return the file format of a given File.   * @param f the file to check   * @return the format of the file   * @throws UnsupportedAudioFileException if the file's format is not    * recognized   * @throws IOException if there is an I/O error reading the file   */  public static AudioFileFormat getAudioFileFormat(File f)    throws UnsupportedAudioFileException, IOException  {    Iterator i = ServiceFactory.lookupProviders(AudioFileReader.class);    while (i.hasNext())      {        AudioFileReader reader = (AudioFileReader) i.next();        try          {            return reader.getAudioFileFormat(f);          }        catch (UnsupportedAudioFileException _)          {            // Try the next provider.          }      }    throw new UnsupportedAudioFileException("file type not recognized");  }  /**   * Return the file format of a given input stream.   * @param is the input stream to check   * @return the format of the stream   * @throws UnsupportedAudioFileException if the stream's format is not    * recognized   * @throws IOException if there is an I/O error reading the stream   */  public static AudioFileFormat getAudioFileFormat(InputStream is)    throws UnsupportedAudioFileException, IOException  {    Iterator i = ServiceFactory.lookupProviders(AudioFileReader.class);    while (i.hasNext())      {        AudioFileReader reader = (AudioFileReader) i.next();        try          {            return reader.getAudioFileFormat(is);          }        catch (UnsupportedAudioFileException _)          {            // Try the next provider.          }      }    throw new UnsupportedAudioFileException("input stream type not recognized");  }  /**   * Return the file format of a given URL.   * @param url the URL to check   * @return the format of the URL   * @throws UnsupportedAudioFileException if the URL's format is not    * recognized   * @throws IOException if there is an I/O error reading the URL   */  public static AudioFileFormat getAudioFileFormat(URL url)    throws UnsupportedAudioFileException, IOException  {    Iterator i = ServiceFactory.lookupProviders(AudioFileReader.class);    while (i.hasNext())      {        AudioFileReader reader = (AudioFileReader) i.next();        try          {            return reader.getAudioFileFormat(url);          }        catch (UnsupportedAudioFileException _)          {            // Try the next provider.          }      }    throw new UnsupportedAudioFileException("URL type not recognized");  }  /**   * Return an array of all the supported AudioFileFormat types.   * @return an array of unique types   */  public static AudioFileFormat.Type[] getAudioFileTypes()  {    HashSet result = new HashSet();    Iterator i = ServiceFactory.lookupProviders(AudioFileWriter.class);    while (i.hasNext())      {        AudioFileWriter writer = (AudioFileWriter) i.next();        AudioFileFormat.Type[] types = writer.getAudioFileTypes();        for (int j = 0; j < types.length; ++j)          result.add(types[j]);      }    return (AudioFileFormat.Type[]) result.toArray(new AudioFileFormat.Type[result.size()]);  }  /**   * Return an array of all the supported AudioFileFormat types which match the   * given audio input stream   * @param ais the audio input stream   * @return an array of unique types   */  public static AudioFileFormat.Type[] getAudioFileTypes(AudioInputStream ais)  {    HashSet result = new HashSet();    Iterator i = ServiceFactory.lookupProviders(AudioFileWriter.class);    while (i.hasNext())      {        AudioFileWriter writer = (AudioFileWriter) i.next();        AudioFileFormat.Type[] types = writer.getAudioFileTypes(ais);        for (int j = 0; j < types.length; ++j)          result.add(types[j]);      }    return (AudioFileFormat.Type[]) result.toArray(new AudioFileFormat.Type[result.size()]);  }  /**   * Given an audio input stream, this will try to create a new audio input   * stream whose encoding matches the given target encoding.  If no provider   * offers this conversion, an exception is thrown.    * @param targ the target encoding   * @param ais the original audio stream   * @return a new audio stream   * @throws IllegalArgumentException if the conversion cannot be made   */  public static AudioInputStream getAudioInputStream(AudioFormat.Encoding targ,						     AudioInputStream ais)  {    HashSet result = new HashSet();    Iterator i = ServiceFactory.lookupProviders(FormatConversionProvider.class);    while (i.hasNext())      {        FormatConversionProvider prov = (FormatConversionProvider) i.next();        if (! prov.isConversionSupported(targ, ais.getFormat()))          continue;        return prov.getAudioInputStream(targ, ais);      }    throw new IllegalArgumentException("encoding not supported for stream"); }  /**   * Given an audio input stream, this will try to create a new audio input   * stream whose format matches the given target format.  If no provider   * offers this conversion, an exception is thrown.    * @param targ the target format   * @param ais the original audio stream   * @return a new audio stream   * @throws IllegalArgumentException if the conversion cannot be made   */  public static AudioInputStream getAudioInputStream(AudioFormat targ,						     AudioInputStream ais)  {    HashSet result = new HashSet();    Iterator i = ServiceFactory.lookupProviders(FormatConversionProvider.class);    while (i.hasNext())      {        FormatConversionProvider prov = (FormatConversionProvider) i.next();        if (! prov.isConversionSupported(targ, ais.getFormat()))          continue;        return prov.getAudioInputStream(targ, ais);      }    throw new IllegalArgumentException("format not supported for stream");   }  /**   * Return an audio input stream for the file.   * @param f the file to read   * @return an audio input stream for the file   * @throws UnsupportedAudioFileException if the file's audio format is not   * recognized   * @throws IOException if there is an error while reading the file   */  public static AudioInputStream getAudioInputStream(File f)    throws UnsupportedAudioFileException, IOException  {    Iterator i = ServiceFactory.lookupProviders(AudioFileReader.class);    while (i.hasNext())      {        AudioFileReader reader = (AudioFileReader) i.next();        try          {            return reader.getAudioInputStream(f);          }        catch (UnsupportedAudioFileException _)          {            // Try the next provider.          }      }    throw new UnsupportedAudioFileException("file type not recognized");  }  /**   * Return an audio input stream given an input stream.   * @param is the input stream   * @return an audio input stream   * @throws UnsupportedAudioFileException if the input stream's audio format   * is not supported by any of the installed providers   * @throws IOException if there is an error while reading the input stream   */  public static AudioInputStream getAudioInputStream(InputStream is)    throws UnsupportedAudioFileException, IOException  {    Iterator i = ServiceFactory.lookupProviders(AudioFileReader.class);    while (i.hasNext())      {        AudioFileReader reader = (AudioFileReader) i.next();        try          {            return reader.getAudioInputStream(is);          }        catch (UnsupportedAudioFileException _)          {            // Try the next provider.          }      }    throw new UnsupportedAudioFileException("input stream type not recognized");  }  /**   * Return an audio input stream for the given URL.   * @param url the URL   * @return an audio input stream   * @throws UnsupportedAudioFileException if the URL's audio format is not   * supported by any of the installed providers   * @throws IOException if there is an error while reading the URL   */  public static AudioInputStream getAudioInputStream(URL url)    throws UnsupportedAudioFileException, IOException  {    Iterator i = ServiceFactory.lookupProviders(AudioFileReader.class);    while (i.hasNext())      {        AudioFileReader reader = (AudioFileReader) i.next();        try          {            return reader.getAudioInputStream(url);          }        catch (UnsupportedAudioFileException _)          {            // Try the next provider.          }      }    throw new UnsupportedAudioFileException("URL type not recognized");  }  /**   * Return a new clip which can be used for playing back an audio stream.   * @throws LineUnavailableException if a clip is not available for some   * reason   * @throws SecurityException if a clip cannot be made for security reasons   * @since 1.5   */  public static Clip getClip()    throws LineUnavailableException  {    Mixer.Info[] infos = getMixerInfo();    for (int i = 0; i < infos.length; ++i)      {        Mixer mix = getMixer(infos[i]);        Line[] lines = mix.getSourceLines();        for (int j = 0; j < lines.length; ++j)          {            if (lines[j] instanceof Clip)              return (Clip) lines[j];          }      }    throw new LineUnavailableException("no Clip available");  }  /**   * Return a new clip which can be used for playing back an audio stream.   * The clip is obtained from the indicated mixer.   * @param info the mixer to use   * @throws LineUnavailableException if a clip is not available for some   * reason   * @throws SecurityException if a clip cannot be made for security reasons   * @since 1.5   */  public static Clip getClip(Mixer.Info info)    throws LineUnavailableException  {    Mixer mix = getMixer(info);    Line[] lines = mix.getSourceLines();    for (int j = 0; j < lines.length; ++j)      {        if (lines[j] instanceof Clip)          return (Clip) lines[j];      }    throw new LineUnavailableException("no Clip available");  }  /**   * Return a line matching the provided description.  All the providers   * on the system are searched for a matching line.   * @param info description of the line   * @return the matching line   * @throws LineUnavailableException if no provider supplies a matching line   */  public static Line getLine(Line.Info info) throws LineUnavailableException  {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -