jdk/src/share/classes/javax/sound/sampled/AudioSystem.java
author ohair
Wed, 06 Apr 2011 22:06:11 -0700
changeset 9035 1255eb81cc2f
parent 8379 3cc0596f81a5
child 15263 f401cac7510b
permissions -rw-r--r--
7033660: Update copyright year to 2011 on any files changed in 2011 Reviewed-by: dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
9035
1255eb81cc2f 7033660: Update copyright year to 2011 on any files changed in 2011
ohair
parents: 8379
diff changeset
     2
 * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.sound.sampled;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.File;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.InputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.OutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.net.URL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.HashSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.List;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.util.Set;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.util.Vector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.util.ArrayList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import javax.sound.sampled.spi.AudioFileWriter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import javax.sound.sampled.spi.AudioFileReader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import javax.sound.sampled.spi.FormatConversionProvider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import javax.sound.sampled.spi.MixerProvider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import com.sun.media.sound.JDK13Services;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
/* $fb TODO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * - consistent usage of (typed) collections
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * The <code>AudioSystem</code> class acts as the entry point to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * sampled-audio system resources. This class lets you query and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * access the mixers that are installed on the system.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * <code>AudioSystem</code> includes a number of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * methods for converting audio data between different formats, and for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * translating between audio files and streams. It also provides a method
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * for obtaining a <code>{@link Line}</code> directly from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * <code>AudioSystem</code> without dealing explicitly
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * with mixers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * <p>Properties can be used to specify the default mixer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * for specific line types.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * Both system properties and a properties file are considered.
6832
cb693e02b3ed 6984047: sound sources needs vendor rebranding changes (jdk7 only)
amenkov
parents: 5506
diff changeset
    66
 * In the Oracle reference implementation, the properties file is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * &quot;lib/sound.properties&quot; in the JRE
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * directory. If a property exists both as a system property and in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * properties file, the system property takes precedence. If none is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * specified, a suitable default is chosen among the available devices.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * The syntax of the properties file is specified in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * {@link java.util.Properties#load(InputStream) Properties.load}. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * following table lists the available property keys and which methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * consider them:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * <table border=0>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 *  <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 *   <th>Property Key</th>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 *   <th>Interface</th>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 *   <th>Affected Method(s)</th>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 *  </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 *  <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 *   <td><code>javax.sound.sampled.Clip</code></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 *   <td>{@link Clip}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 *   <td>{@link #getLine}, {@link #getClip}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 *  </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 *  <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 *   <td><code>javax.sound.sampled.Port</code></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 *   <td>{@link Port}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 *   <td>{@link #getLine}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 *  </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 *  <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 *   <td><code>javax.sound.sampled.SourceDataLine</code></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 *   <td>{@link SourceDataLine}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 *   <td>{@link #getLine}, {@link #getSourceDataLine}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 *  </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 *  <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 *   <td><code>javax.sound.sampled.TargetDataLine</code></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 *   <td>{@link TargetDataLine}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 *   <td>{@link #getLine}, {@link #getTargetDataLine}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 *  </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 * </table>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 * The property value consists of the provider class name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 * and the mixer name, separated by the hash mark (&quot;#&quot;).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 * The provider class name is the fully-qualified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 * name of a concrete {@link javax.sound.sampled.spi.MixerProvider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 * mixer provider} class. The mixer name is matched against
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 * the <code>String</code> returned by the <code>getName</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 * method of <code>Mixer.Info</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 * Either the class name, or the mixer name may be omitted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 * If only the class name is specified, the trailing hash mark
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 * is optional.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 * <p>If the provider class is specified, and it can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 * successully retrieved from the installed providers, the list of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 * <code>Mixer.Info</code> objects is retrieved
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 * from the provider. Otherwise, or when these mixers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 * do not provide a subsequent match, the list is retrieved
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 * from {@link #getMixerInfo} to contain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 * all available <code>Mixer.Info</code> objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 * <p>If a mixer name is specified, the resulting list of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
 * <code>Mixer.Info</code> objects is searched:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
 * the first one with a matching name, and whose
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
 * <code>Mixer</code> provides the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
 * respective line interface, will be returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
 * If no matching <code>Mixer.Info</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
 * is found, or the mixer name is not specified,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
 * the first mixer from the resulting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
 * list, which provides the respective line
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
 * interface, will be returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
 * For example, the property <code>javax.sound.sampled.Clip</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
 * with a value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
 * <code>&quot;com.sun.media.sound.MixerProvider#SunClip&quot;</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
 * will have the following consequences when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
 * <code>getLine</code> is called requesting a <code>Clip</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
 * instance:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
 * if the class <code>com.sun.media.sound.MixerProvider</code> exists
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
 * in the list of installed mixer providers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
 * the first <code>Clip</code> from the first mixer with name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
 * <code>&quot;SunClip&quot;</code> will be returned. If it cannot
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
 * be found, the first <code>Clip</code> from the first mixer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
 * of the specified provider will be returned, regardless of name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
 * If there is none, the first <code>Clip</code> from the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
 * <code>Mixer</code> with name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
 * <code>&quot;SunClip&quot;</code> in the list of all mixers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
 * (as returned by <code>getMixerInfo</code>) will be returned,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
 * or, if not found, the first <code>Clip</code> of the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
 * <code>Mixer</code>that can be found in the list of all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
 * mixers is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
 * If that fails, too, an <code>IllegalArgumentException</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
 * is thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
 * @author Kara Kytle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
 * @author Florian Bomers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
 * @author Matthias Pfisterer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
 * @author Kevin P. Smith
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
 * @see AudioFormat
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
 * @see AudioInputStream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
 * @see Mixer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
 * @see Line
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
 * @see Line.Info
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
 * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
public class AudioSystem {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * An integer that stands for an unknown numeric value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * This value is appropriate only for signed quantities that do not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * normally take negative values.  Examples include file sizes, frame
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * sizes, buffer sizes, and sample rates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * A number of Java Sound constructors accept
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * a value of <code>NOT_SPECIFIED</code> for such parameters.  Other
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * methods may also accept or return this value, as documented.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    public static final int NOT_SPECIFIED = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * Private no-args constructor for ensuring against instantiation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    private AudioSystem() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * Obtains an array of mixer info objects that represents
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * the set of audio mixers that are currently installed on the system.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * @return an array of info objects for the currently installed mixers.  If no mixers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * are available on the system, an array of length 0 is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * @see #getMixer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    public static Mixer.Info[] getMixerInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        List infos = getMixerInfoList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        Mixer.Info[] allInfos = (Mixer.Info[]) infos.toArray(new Mixer.Info[infos.size()]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        return allInfos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * Obtains the requested audio mixer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * @param info a <code>Mixer.Info</code> object representing the desired
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * mixer, or <code>null</code> for the system default mixer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * @return the requested mixer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * @throws SecurityException if the requested mixer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * is unavailable because of security restrictions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * @throws IllegalArgumentException if the info object does not represent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * a mixer installed on the system
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * @see #getMixerInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    public static Mixer getMixer(Mixer.Info info) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        Mixer mixer = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        List providers = getMixerProviders();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        for(int i = 0; i < providers.size(); i++ ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                return ((MixerProvider)providers.get(i)).getMixer(info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            } catch (IllegalArgumentException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            } catch (NullPointerException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                // $$jb 08.20.99:  If the strings in the info object aren't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                // set, then Netscape (using jdk1.1.5) tends to throw
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                // NPE's when doing some string manipulation.  This is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                // probably not the best fix, but is solves the problem
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                // of the NPE in Netscape using local classes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                // $$jb 11.01.99: Replacing this patch.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        //$$fb if looking for default mixer, and not found yet, add a round of looking
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        if (info == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            for(int i = 0; i < providers.size(); i++ ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                    MixerProvider provider = (MixerProvider) providers.get(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                    Mixer.Info[] infos = provider.getMixerInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                    // start from 0 to last device (do not reverse this order)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                    for (int ii = 0; ii < infos.length; ii++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                            return provider.getMixer(infos[ii]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                        } catch (IllegalArgumentException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                            // this is not a good default device :)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                } catch (IllegalArgumentException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                } catch (NullPointerException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        throw new IllegalArgumentException("Mixer not supported: "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                                           + (info!=null?info.toString():"null"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    //$$fb 2002-11-26: fix for 4757930: DOC: AudioSystem.getTarget/SourceLineInfo() is ambiguous
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * Obtains information about all source lines of a particular type that are supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * by the installed mixers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * @param info a <code>Line.Info</code> object that specifies the kind of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * lines about which information is requested
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * @return an array of <code>Line.Info</code> objects describing source lines matching
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * the type requested.  If no matching source lines are supported, an array of length 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * @see Mixer#getSourceLineInfo(Line.Info)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    public static Line.Info[] getSourceLineInfo(Line.Info info) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        Vector vector = new Vector();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        Line.Info[] currentInfoArray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        Mixer mixer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        Line.Info fullInfo = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        Mixer.Info[] infoArray = getMixerInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        for (int i = 0; i < infoArray.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            mixer = getMixer(infoArray[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            currentInfoArray = mixer.getSourceLineInfo(info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            for (int j = 0; j < currentInfoArray.length; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                vector.addElement(currentInfoArray[j]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        Line.Info[] returnedArray = new Line.Info[vector.size()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        for (int i = 0; i < returnedArray.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            returnedArray[i] = (Line.Info)vector.get(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        return returnedArray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * Obtains information about all target lines of a particular type that are supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * by the installed mixers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * @param info a <code>Line.Info</code> object that specifies the kind of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * lines about which information is requested
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * @return an array of <code>Line.Info</code> objects describing target lines matching
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * the type requested.  If no matching target lines are supported, an array of length 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * @see Mixer#getTargetLineInfo(Line.Info)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    public static Line.Info[] getTargetLineInfo(Line.Info info) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        Vector vector = new Vector();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        Line.Info[] currentInfoArray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        Mixer mixer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        Line.Info fullInfo = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        Mixer.Info[] infoArray = getMixerInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        for (int i = 0; i < infoArray.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            mixer = getMixer(infoArray[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
            currentInfoArray = mixer.getTargetLineInfo(info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            for (int j = 0; j < currentInfoArray.length; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                vector.addElement(currentInfoArray[j]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        Line.Info[] returnedArray = new Line.Info[vector.size()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        for (int i = 0; i < returnedArray.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            returnedArray[i] = (Line.Info)vector.get(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        return returnedArray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * Indicates whether the system supports any lines that match
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * the specified <code>Line.Info</code> object.  A line is supported if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * any installed mixer supports it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * @param info a <code>Line.Info</code> object describing the line for which support is queried
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * @return <code>true</code> if at least one matching line is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * supported, otherwise <code>false</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * @see Mixer#isLineSupported(Line.Info)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    public static boolean isLineSupported(Line.Info info) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        Mixer mixer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        Mixer.Info[] infoArray = getMixerInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        for (int i = 0; i < infoArray.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            if( infoArray[i] != null ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                mixer = getMixer(infoArray[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                if (mixer.isLineSupported(info)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * Obtains a line that matches the description in the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * <code>Line.Info</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     * <p>If a <code>DataLine</code> is requested, and <code>info</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * is an instance of <code>DataLine.Info</code> specifying at least
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * one fully qualified audio format, the last one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     * will be used as the default format of the returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     * <code>DataLine</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     * <p>If system properties
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     * <code>javax.sound.sampled.Clip</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * <code>javax.sound.sampled.Port</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     * <code>javax.sound.sampled.SourceDataLine</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     * <code>javax.sound.sampled.TargetDataLine</code> are defined
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     * or they are defined in the file &quot;sound.properties&quot;,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     * they are used to retrieve default lines.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * For details, refer to the {@link AudioSystem class description}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     * If the respective property is not set, or the mixer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * requested in the property is not installed or does not provide the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * requested line, all installed mixers are queried for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * requested line type. A Line will be returned from the first mixer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * providing the requested line type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * @param info a <code>Line.Info</code> object describing the desired kind of line
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * @return a line of the requested kind
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * @throws LineUnavailableException if a matching line
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     * is not available due to resource restrictions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * @throws SecurityException if a matching line
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * is not available due to security restrictions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * @throws IllegalArgumentException if the system does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * support at least one line matching the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * <code>Line.Info</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * through any installed mixer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    public static Line getLine(Line.Info info) throws LineUnavailableException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        LineUnavailableException lue = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        List providers = getMixerProviders();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        // 1: try from default mixer for this line class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
            Mixer mixer = getDefaultMixer(providers, info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            if (mixer != null && mixer.isLineSupported(info)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
                return mixer.getLine(info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        } catch (LineUnavailableException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
            lue = e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        } catch (IllegalArgumentException iae) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
            // must not happen... but better to catch it here,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
            // if plug-ins are badly written
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        // 2: if that doesn't work, try to find any mixing mixer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        for(int i = 0; i < providers.size(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            MixerProvider provider = (MixerProvider) providers.get(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
            Mixer.Info[] infos = provider.getMixerInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            for (int j = 0; j < infos.length; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                    Mixer mixer = provider.getMixer(infos[j]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                    // see if this is an appropriate mixer which can mix
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                    if (isAppropriateMixer(mixer, info, true)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                        return mixer.getLine(info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                } catch (LineUnavailableException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                    lue = e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                } catch (IllegalArgumentException iae) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                    // must not happen... but better to catch it here,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                    // if plug-ins are badly written
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        // 3: if that didn't work, try to find any non-mixing mixer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        for(int i = 0; i < providers.size(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
            MixerProvider provider = (MixerProvider) providers.get(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
            Mixer.Info[] infos = provider.getMixerInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            for (int j = 0; j < infos.length; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
                    Mixer mixer = provider.getMixer(infos[j]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                    // see if this is an appropriate mixer which can mix
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                    if (isAppropriateMixer(mixer, info, false)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                        return mixer.getLine(info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                } catch (LineUnavailableException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                    lue = e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                } catch (IllegalArgumentException iae) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                    // must not happen... but better to catch it here,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                    // if plug-ins are badly written
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        // if this line was supported but was not available, throw the last
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        // LineUnavailableException we got (??).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        if (lue != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
            throw lue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        // otherwise, the requested line was not supported, so throw
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        // an Illegal argument exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        throw new IllegalArgumentException("No line matching " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                                           info.toString() + " is supported.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     * Obtains a clip that can be used for playing back
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     * an audio file or an audio stream. The returned clip
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     * will be provided by the default system mixer, or,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     * if not possible, by any other mixer installed in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     * system that supports a <code>Clip</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     * object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     * <p>The returned clip must be opened with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     * <code>open(AudioFormat)</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     * <code>open(AudioInputStream)</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     * <p>This is a high-level method that uses <code>getMixer</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     * and <code>getLine</code> internally.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     * <p>If the system property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     * <code>javax.sound.sampled.Clip</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     * is defined or it is defined in the file &quot;sound.properties&quot;,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     * it is used to retrieve the default clip.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     * For details, refer to the {@link AudioSystem class description}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     * @return the desired clip object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     * @throws LineUnavailableException if a clip object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     * is not available due to resource restrictions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     * @throws SecurityException if a clip object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     * is not available due to security restrictions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     * @throws IllegalArgumentException if the system does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     * support at least one clip instance through any installed mixer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     * @see #getClip(Mixer.Info)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
    public static Clip getClip() throws LineUnavailableException{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        AudioFormat format = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
                                             AudioSystem.NOT_SPECIFIED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
                                             16, 2, 4,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
                                             AudioSystem.NOT_SPECIFIED, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        DataLine.Info info = new DataLine.Info(Clip.class, format);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        return (Clip) AudioSystem.getLine(info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
     * Obtains a clip from the specified mixer that can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     * used for playing back an audio file or an audio stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     * <p>The returned clip must be opened with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     * <code>open(AudioFormat)</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     * <code>open(AudioInputStream)</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     * <p>This is a high-level method that uses <code>getMixer</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     * and <code>getLine</code> internally.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     * @param mixerInfo a <code>Mixer.Info</code> object representing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     * desired mixer, or <code>null</code> for the system default mixer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     * @return a clip object from the specified mixer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     * @throws LineUnavailableException if a clip
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     * is not available from this mixer due to resource restrictions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
     * @throws SecurityException if a clip
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
     * is not available from this mixer due to security restrictions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
     * @throws IllegalArgumentException if the system does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     * support at least one clip through the specified mixer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
     * @see #getClip()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
    public static Clip getClip(Mixer.Info mixerInfo) throws LineUnavailableException{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        AudioFormat format = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                                             AudioSystem.NOT_SPECIFIED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
                                             16, 2, 4,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
                                             AudioSystem.NOT_SPECIFIED, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
        DataLine.Info info = new DataLine.Info(Clip.class, format);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        Mixer mixer = AudioSystem.getMixer(mixerInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
        return (Clip) mixer.getLine(info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
     * Obtains a source data line that can be used for playing back
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
     * audio data in the format specified by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     * <code>AudioFormat</code> object. The returned line
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
     * will be provided by the default system mixer, or,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
     * if not possible, by any other mixer installed in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
     * system that supports a matching
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
     * <code>SourceDataLine</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
     * <p>The returned line should be opened with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
     * <code>open(AudioFormat)</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
     * <code>open(AudioFormat, int)</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
     * <p>This is a high-level method that uses <code>getMixer</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     * and <code>getLine</code> internally.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     * <p>The returned <code>SourceDataLine</code>'s default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
     * audio format will be initialized with <code>format</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     * <p>If the system property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
     * <code>javax.sound.sampled.SourceDataLine</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
     * is defined or it is defined in the file &quot;sound.properties&quot;,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
     * it is used to retrieve the default source data line.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     * For details, refer to the {@link AudioSystem class description}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     * @param format an <code>AudioFormat</code> object specifying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
     *        the supported audio format of the returned line,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
     *        or <code>null</code> for any audio format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
     * @return the desired <code>SourceDataLine</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
     * @throws LineUnavailableException if a matching source data line
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     *         is not available due to resource restrictions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     * @throws SecurityException if a matching source data line
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     *         is not available due to security restrictions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
     * @throws IllegalArgumentException if the system does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     *         support at least one source data line supporting the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     *         specified audio format through any installed mixer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
     * @see #getSourceDataLine(AudioFormat, Mixer.Info)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
    public static SourceDataLine getSourceDataLine(AudioFormat format)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
        throws LineUnavailableException{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        DataLine.Info info = new DataLine.Info(SourceDataLine.class, format);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
        return (SourceDataLine) AudioSystem.getLine(info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
     * Obtains a source data line that can be used for playing back
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
     * audio data in the format specified by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
     * <code>AudioFormat</code> object, provided by the mixer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
     * specified by the <code>Mixer.Info</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
     * <p>The returned line should be opened with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
     * <code>open(AudioFormat)</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
     * <code>open(AudioFormat, int)</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
     * <p>This is a high-level method that uses <code>getMixer</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
     * and <code>getLine</code> internally.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
     * <p>The returned <code>SourceDataLine</code>'s default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
     * audio format will be initialized with <code>format</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
     * @param format an <code>AudioFormat</code> object specifying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
     *        the supported audio format of the returned line,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
     *        or <code>null</code> for any audio format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
     * @param mixerinfo a <code>Mixer.Info</code> object representing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
     *        the desired mixer, or <code>null</code> for the system
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
     *        default mixer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
     * @return the desired <code>SourceDataLine</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
     * @throws LineUnavailableException if a matching source data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
     *         line is not available from the specified mixer due
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
     *         to resource restrictions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
     * @throws SecurityException if a matching source data line
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
     *         is not available from the specified mixer due to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
     *         security restrictions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
     * @throws IllegalArgumentException if the specified mixer does
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
     *         not support at least one source data line supporting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
     *         the specified audio format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
     * @see #getSourceDataLine(AudioFormat)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
    public static SourceDataLine getSourceDataLine(AudioFormat format,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
                                                   Mixer.Info mixerinfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
        throws LineUnavailableException{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
        DataLine.Info info = new DataLine.Info(SourceDataLine.class, format);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
        Mixer mixer = AudioSystem.getMixer(mixerinfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
        return (SourceDataLine) mixer.getLine(info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
     * Obtains a target data line that can be used for recording
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
     * audio data in the format specified by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
     * <code>AudioFormat</code> object. The returned line
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
     * will be provided by the default system mixer, or,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
     * if not possible, by any other mixer installed in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
     * system that supports a matching
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
     * <code>TargetDataLine</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
     * <p>The returned line should be opened with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
     * <code>open(AudioFormat)</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
     * <code>open(AudioFormat, int)</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
     * <p>This is a high-level method that uses <code>getMixer</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
     * and <code>getLine</code> internally.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
     * <p>The returned <code>TargetDataLine</code>'s default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
     * audio format will be initialized with <code>format</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
     *
8379
3cc0596f81a5 7000132: Misplaced description in javax.sound.sampled.AudioSystem.getTargetDataLine
amenkov
parents: 6832
diff changeset
   673
     * <p>If the system property
3cc0596f81a5 7000132: Misplaced description in javax.sound.sampled.AudioSystem.getTargetDataLine
amenkov
parents: 6832
diff changeset
   674
     * {@code javax.sound.sampled.TargetDataLine}
3cc0596f81a5 7000132: Misplaced description in javax.sound.sampled.AudioSystem.getTargetDataLine
amenkov
parents: 6832
diff changeset
   675
     * is defined or it is defined in the file &quot;sound.properties&quot;,
3cc0596f81a5 7000132: Misplaced description in javax.sound.sampled.AudioSystem.getTargetDataLine
amenkov
parents: 6832
diff changeset
   676
     * it is used to retrieve the default target data line.
3cc0596f81a5 7000132: Misplaced description in javax.sound.sampled.AudioSystem.getTargetDataLine
amenkov
parents: 6832
diff changeset
   677
     * For details, refer to the {@link AudioSystem class description}.
3cc0596f81a5 7000132: Misplaced description in javax.sound.sampled.AudioSystem.getTargetDataLine
amenkov
parents: 6832
diff changeset
   678
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
     * @param format an <code>AudioFormat</code> object specifying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
     *        the supported audio format of the returned line,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
     *        or <code>null</code> for any audio format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
     * @return the desired <code>TargetDataLine</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
     * @throws LineUnavailableException if a matching target data line
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
     *         is not available due to resource restrictions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
     * @throws SecurityException if a matching target data line
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
     *         is not available due to security restrictions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
     * @throws IllegalArgumentException if the system does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
     *         support at least one target data line supporting the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
     *         specified audio format through any installed mixer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
     * @see #getTargetDataLine(AudioFormat, Mixer.Info)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
     * @see AudioPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
    public static TargetDataLine getTargetDataLine(AudioFormat format)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
        throws LineUnavailableException{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
        DataLine.Info info = new DataLine.Info(TargetDataLine.class, format);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
        return (TargetDataLine) AudioSystem.getLine(info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
     * Obtains a target data line that can be used for recording
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
     * audio data in the format specified by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
     * <code>AudioFormat</code> object, provided by the mixer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
     * specified by the <code>Mixer.Info</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
     * <p>The returned line should be opened with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
     * <code>open(AudioFormat)</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
     * <code>open(AudioFormat, int)</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
     * <p>This is a high-level method that uses <code>getMixer</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
     * and <code>getLine</code> internally.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
     * <p>The returned <code>TargetDataLine</code>'s default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
     * audio format will be initialized with <code>format</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
     * @param format an <code>AudioFormat</code> object specifying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
     *        the supported audio format of the returned line,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
     *        or <code>null</code> for any audio format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
     * @param mixerinfo a <code>Mixer.Info</code> object representing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
     *        desired mixer, or <code>null</code> for the system default mixer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
     * @return the desired <code>TargetDataLine</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
     * @throws LineUnavailableException if a matching target data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
     *         line is not available from the specified mixer due
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
     *         to resource restrictions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
     * @throws SecurityException if a matching target data line
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
     *         is not available from the specified mixer due to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
     *         security restrictions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
     * @throws IllegalArgumentException if the specified mixer does
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
     *         not support at least one target data line supporting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
     *         the specified audio format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
     * @see #getTargetDataLine(AudioFormat)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
     * @see AudioPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
    public static TargetDataLine getTargetDataLine(AudioFormat format,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
                                                   Mixer.Info mixerinfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
        throws LineUnavailableException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
        DataLine.Info info = new DataLine.Info(TargetDataLine.class, format);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
        Mixer mixer = AudioSystem.getMixer(mixerinfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
        return (TargetDataLine) mixer.getLine(info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
    // $$fb 2002-04-12: fix for 4662082: behavior of AudioSystem.getTargetEncodings() methods doesn't match the spec
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
     * Obtains the encodings that the system can obtain from an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
     * audio input stream with the specified encoding using the set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
     * of installed format converters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
     * @param sourceEncoding the encoding for which conversion support
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
     * is queried
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
     * @return array of encodings.  If <code>sourceEncoding</code>is not supported,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
     * an array of length 0 is returned. Otherwise, the array will have a length
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
     * of at least 1, representing <code>sourceEncoding</code> (no conversion).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
    public static AudioFormat.Encoding[] getTargetEncodings(AudioFormat.Encoding sourceEncoding) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
        List codecs = getFormatConversionProviders();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
        Vector encodings = new Vector();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
        AudioFormat.Encoding encs[] = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
        // gather from all the codecs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
        for(int i=0; i<codecs.size(); i++ ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
            FormatConversionProvider codec = (FormatConversionProvider) codecs.get(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
            if( codec.isSourceEncodingSupported( sourceEncoding ) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
                encs = codec.getTargetEncodings();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
                for (int j = 0; j < encs.length; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
                    encodings.addElement( encs[j] );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
        AudioFormat.Encoding encs2[] = (AudioFormat.Encoding[]) encodings.toArray(new AudioFormat.Encoding[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
        return encs2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
    // $$fb 2002-04-12: fix for 4662082: behavior of AudioSystem.getTargetEncodings() methods doesn't match the spec
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
     * Obtains the encodings that the system can obtain from an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
     * audio input stream with the specified format using the set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
     * of installed format converters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
     * @param sourceFormat the audio format for which conversion
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
     * is queried
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
     * @return array of encodings. If <code>sourceFormat</code>is not supported,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
     * an array of length 0 is returned. Otherwise, the array will have a length
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
     * of at least 1, representing the encoding of <code>sourceFormat</code> (no conversion).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
    public static AudioFormat.Encoding[] getTargetEncodings(AudioFormat sourceFormat) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
        List codecs = getFormatConversionProviders();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
        Vector encodings = new Vector();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
        int size = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
        int index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
        AudioFormat.Encoding encs[] = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
        // gather from all the codecs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
        for(int i=0; i<codecs.size(); i++ ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
            encs = ((FormatConversionProvider) codecs.get(i)).getTargetEncodings(sourceFormat);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
            size += encs.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
            encodings.addElement( encs );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
        // now build a new array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
        AudioFormat.Encoding encs2[] = new AudioFormat.Encoding[size];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
        for(int i=0; i<encodings.size(); i++ ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
            encs = (AudioFormat.Encoding [])(encodings.get(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
            for(int j=0; j<encs.length; j++ ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
                encs2[index++] = encs[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
        return encs2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
     * Indicates whether an audio input stream of the specified encoding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
     * can be obtained from an audio input stream that has the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
     * format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
     * @param targetEncoding the desired encoding after conversion
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
     * @param sourceFormat the audio format before conversion
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
     * @return <code>true</code> if the conversion is supported,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
     * otherwise <code>false</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
    public static boolean isConversionSupported(AudioFormat.Encoding targetEncoding, AudioFormat sourceFormat) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
        List codecs = getFormatConversionProviders();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
        for(int i=0; i<codecs.size(); i++ ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
            FormatConversionProvider codec = (FormatConversionProvider) codecs.get(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
            if(codec.isConversionSupported(targetEncoding,sourceFormat) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
     * Obtains an audio input stream of the indicated encoding, by converting the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
     * provided audio input stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
     * @param targetEncoding the desired encoding after conversion
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
     * @param sourceStream the stream to be converted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
     * @return an audio input stream of the indicated encoding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
     * @throws IllegalArgumentException if the conversion is not supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
     * @see #getTargetEncodings(AudioFormat.Encoding)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
     * @see #getTargetEncodings(AudioFormat)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
     * @see #isConversionSupported(AudioFormat.Encoding, AudioFormat)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
     * @see #getAudioInputStream(AudioFormat, AudioInputStream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
    public static AudioInputStream getAudioInputStream(AudioFormat.Encoding targetEncoding,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
                                                       AudioInputStream sourceStream) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
        List codecs = getFormatConversionProviders();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
        for(int i = 0; i < codecs.size(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
            FormatConversionProvider codec = (FormatConversionProvider) codecs.get(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
            if( codec.isConversionSupported( targetEncoding, sourceStream.getFormat() ) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
                return codec.getAudioInputStream( targetEncoding, sourceStream );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
        // we ran out of options, throw an exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
        throw new IllegalArgumentException("Unsupported conversion: " + targetEncoding + " from " + sourceStream.getFormat());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
     * Obtains the formats that have a particular encoding and that the system can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
     * obtain from a stream of the specified format using the set of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
     * installed format converters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
     * @param targetEncoding the desired encoding after conversion
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
     * @param sourceFormat the audio format before conversion
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
     * @return array of formats.  If no formats of the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
     * encoding are supported, an array of length 0 is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
    public static AudioFormat[] getTargetFormats(AudioFormat.Encoding targetEncoding, AudioFormat sourceFormat) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
        List codecs = getFormatConversionProviders();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
        Vector formats = new Vector();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
        int size = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
        int index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
        AudioFormat fmts[] = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
        // gather from all the codecs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
        for(int i=0; i<codecs.size(); i++ ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
            FormatConversionProvider codec = (FormatConversionProvider) codecs.get(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
            fmts = codec.getTargetFormats(targetEncoding, sourceFormat);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
            size += fmts.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
            formats.addElement( fmts );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
        // now build a new array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
        AudioFormat fmts2[] = new AudioFormat[size];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
        for(int i=0; i<formats.size(); i++ ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
            fmts = (AudioFormat [])(formats.get(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
            for(int j=0; j<fmts.length; j++ ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
                fmts2[index++] = fmts[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
        return fmts2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
     * Indicates whether an audio input stream of a specified format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
     * can be obtained from an audio input stream of another specified format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
     * @param targetFormat the desired audio format after conversion
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
     * @param sourceFormat the audio format before conversion
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
     * @return <code>true</code> if the conversion is supported,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
     * otherwise <code>false</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
    public static boolean isConversionSupported(AudioFormat targetFormat, AudioFormat sourceFormat) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
        List codecs = getFormatConversionProviders();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
        for(int i=0; i<codecs.size(); i++ ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
            FormatConversionProvider codec = (FormatConversionProvider) codecs.get(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
            if(codec.isConversionSupported(targetFormat, sourceFormat) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
     * Obtains an audio input stream of the indicated format, by converting the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
     * provided audio input stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
     * @param targetFormat the desired audio format after conversion
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
     * @param sourceStream the stream to be converted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
     * @return an audio input stream of the indicated format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
     * @throws IllegalArgumentException if the conversion is not supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
     * #see #getTargetEncodings(AudioFormat)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
     * @see #getTargetFormats(AudioFormat.Encoding, AudioFormat)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
     * @see #isConversionSupported(AudioFormat, AudioFormat)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
     * @see #getAudioInputStream(AudioFormat.Encoding, AudioInputStream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
    public static AudioInputStream getAudioInputStream(AudioFormat targetFormat,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
                                                       AudioInputStream sourceStream) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
        if (sourceStream.getFormat().matches(targetFormat)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
            return sourceStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
        List codecs = getFormatConversionProviders();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
        for(int i = 0; i < codecs.size(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
            FormatConversionProvider codec = (FormatConversionProvider) codecs.get(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
            if(codec.isConversionSupported(targetFormat,sourceStream.getFormat()) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
                return codec.getAudioInputStream(targetFormat,sourceStream);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
        // we ran out of options...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
        throw new IllegalArgumentException("Unsupported conversion: " + targetFormat + " from " + sourceStream.getFormat());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
     * Obtains the audio file format of the provided input stream.  The stream must
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
     * point to valid audio file data.  The implementation of this method may require
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
     * multiple parsers to examine the stream to determine whether they support it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
     * These parsers must be able to mark the stream, read enough data to determine whether they
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
     * support the stream, and, if not, reset the stream's read pointer to its original
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
     * position.  If the input stream does not support these operations, this method may fail
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
     * with an <code>IOException</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
     * @param stream the input stream from which file format information should be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
     * extracted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
     * @return an <code>AudioFileFormat</code> object describing the stream's audio file format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
     * @throws UnsupportedAudioFileException if the stream does not point to valid audio
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
     * file data recognized by the system
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
     * @throws IOException if an input/output exception occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
     * @see InputStream#markSupported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
     * @see InputStream#mark
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
    public static AudioFileFormat getAudioFileFormat(InputStream stream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
        throws UnsupportedAudioFileException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
        List providers = getAudioFileReaders();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
        AudioFileFormat format = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
        for(int i = 0; i < providers.size(); i++ ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
            AudioFileReader reader = (AudioFileReader) providers.get(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
                format = reader.getAudioFileFormat( stream ); // throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
            } catch (UnsupportedAudioFileException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
        if( format==null ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
            throw new UnsupportedAudioFileException("file is not a supported file type");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
            return format;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
     * Obtains the audio file format of the specified URL.  The URL must
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
     * point to valid audio file data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
     * @param url the URL from which file format information should be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
     * extracted
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
     * @return an <code>AudioFileFormat</code> object describing the audio file format
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
     * @throws UnsupportedAudioFileException if the URL does not point to valid audio
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
     * file data recognized by the system
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
     * @throws IOException if an input/output exception occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
    public static AudioFileFormat getAudioFileFormat(URL url)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
        throws UnsupportedAudioFileException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
        List providers = getAudioFileReaders();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
        AudioFileFormat format = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
        for(int i = 0; i < providers.size(); i++ ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
            AudioFileReader reader = (AudioFileReader) providers.get(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
                format = reader.getAudioFileFormat( url ); // throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
            } catch (UnsupportedAudioFileException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
        if( format==null ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
            throw new UnsupportedAudioFileException("file is not a supported file type");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
            return format;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
     * Obtains the audio file format of the specified <code>File</code>.  The <code>File</code> must
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
     * point to valid audio file data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
     * @param file the <code>File</code> from which file format information should be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
     * extracted
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
     * @return an <code>AudioFileFormat</code> object describing the audio file format
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
     * @throws UnsupportedAudioFileException if the <code>File</code> does not point to valid audio
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
     * file data recognized by the system
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
     * @throws IOException if an I/O exception occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
    public static AudioFileFormat getAudioFileFormat(File file)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
        throws UnsupportedAudioFileException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
        List providers = getAudioFileReaders();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
        AudioFileFormat format = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
        for(int i = 0; i < providers.size(); i++ ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
            AudioFileReader reader = (AudioFileReader) providers.get(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
                format = reader.getAudioFileFormat( file ); // throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
            } catch (UnsupportedAudioFileException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
        if( format==null ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
            throw new UnsupportedAudioFileException("file is not a supported file type");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
            return format;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
     * Obtains an audio input stream from the provided input stream.  The stream must
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
     * point to valid audio file data.  The implementation of this method may
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
     * require multiple parsers to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
     * examine the stream to determine whether they support it.  These parsers must
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
     * be able to mark the stream, read enough data to determine whether they
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
     * support the stream, and, if not, reset the stream's read pointer to its original
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
     * position.  If the input stream does not support these operation, this method may fail
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
     * with an <code>IOException</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
     * @param stream the input stream from which the <code>AudioInputStream</code> should be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
     * constructed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
     * @return an <code>AudioInputStream</code> object based on the audio file data contained
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
     * in the input stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
     * @throws UnsupportedAudioFileException if the stream does not point to valid audio
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
     * file data recognized by the system
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
     * @throws IOException if an I/O exception occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
     * @see InputStream#markSupported
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
     * @see InputStream#mark
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
    public static AudioInputStream getAudioInputStream(InputStream stream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
        throws UnsupportedAudioFileException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
        List providers = getAudioFileReaders();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
        AudioInputStream audioStream = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
        for(int i = 0; i < providers.size(); i++ ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
            AudioFileReader reader = (AudioFileReader) providers.get(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
                audioStream = reader.getAudioInputStream( stream ); // throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
            } catch (UnsupportedAudioFileException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
        if( audioStream==null ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
            throw new UnsupportedAudioFileException("could not get audio input stream from input stream");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
            return audioStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
     * Obtains an audio input stream from the URL provided.  The URL must
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
     * point to valid audio file data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
     * @param url the URL for which the <code>AudioInputStream</code> should be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
     * constructed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
     * @return an <code>AudioInputStream</code> object based on the audio file data pointed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
     * to by the URL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
     * @throws UnsupportedAudioFileException if the URL does not point to valid audio
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
     * file data recognized by the system
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
     * @throws IOException if an I/O exception occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
    public static AudioInputStream getAudioInputStream(URL url)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
        throws UnsupportedAudioFileException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
        List providers = getAudioFileReaders();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
        AudioInputStream audioStream = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
        for(int i = 0; i < providers.size(); i++ ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
            AudioFileReader reader = (AudioFileReader) providers.get(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
                audioStream = reader.getAudioInputStream( url ); // throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
            } catch (UnsupportedAudioFileException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
        if( audioStream==null ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
            throw new UnsupportedAudioFileException("could not get audio input stream from input URL");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
            return audioStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
     * Obtains an audio input stream from the provided <code>File</code>.  The <code>File</code> must
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
     * point to valid audio file data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
     * @param file the <code>File</code> for which the <code>AudioInputStream</code> should be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
     * constructed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
     * @return an <code>AudioInputStream</code> object based on the audio file data pointed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
     * to by the <code>File</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
     * @throws UnsupportedAudioFileException if the <code>File</code> does not point to valid audio
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
     * file data recognized by the system
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
     * @throws IOException if an I/O exception occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
    public static AudioInputStream getAudioInputStream(File file)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
        throws UnsupportedAudioFileException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
        List providers = getAudioFileReaders();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
        AudioInputStream audioStream = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
        for(int i = 0; i < providers.size(); i++ ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
            AudioFileReader reader = (AudioFileReader) providers.get(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
                audioStream = reader.getAudioInputStream( file ); // throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
            } catch (UnsupportedAudioFileException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
        if( audioStream==null ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
            throw new UnsupportedAudioFileException("could not get audio input stream from input file");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
            return audioStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
     * Obtains the file types for which file writing support is provided by the system.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
     * @return array of unique file types.  If no file types are supported,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
     * an array of length 0 is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
    public static AudioFileFormat.Type[] getAudioFileTypes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
        List providers = getAudioFileWriters();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
        Set returnTypesSet = new HashSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
        for(int i=0; i < providers.size(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
            AudioFileWriter writer = (AudioFileWriter) providers.get(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
            AudioFileFormat.Type[] fileTypes = writer.getAudioFileTypes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
            for(int j=0; j < fileTypes.length; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
                returnTypesSet.add(fileTypes[j]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
        AudioFileFormat.Type returnTypes[] = (AudioFileFormat.Type[])
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
            returnTypesSet.toArray(new AudioFileFormat.Type[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
        return returnTypes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
     * Indicates whether file writing support for the specified file type is provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
     * by the system.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
     * @param fileType the file type for which write capabilities are queried
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
     * @return <code>true</code> if the file type is supported,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
     * otherwise <code>false</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
    public static boolean isFileTypeSupported(AudioFileFormat.Type fileType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
        List providers = getAudioFileWriters();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
        for(int i=0; i < providers.size(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
            AudioFileWriter writer = (AudioFileWriter) providers.get(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
            if (writer.isFileTypeSupported(fileType)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
     * Obtains the file types that the system can write from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
     * audio input stream specified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
     * @param stream the audio input stream for which audio file type support
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
     * is queried
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
     * @return array of file types.  If no file types are supported,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
     * an array of length 0 is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
    public static AudioFileFormat.Type[] getAudioFileTypes(AudioInputStream stream) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
        List providers = getAudioFileWriters();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
        Set returnTypesSet = new HashSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
        for(int i=0; i < providers.size(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
            AudioFileWriter writer = (AudioFileWriter) providers.get(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
            AudioFileFormat.Type[] fileTypes = writer.getAudioFileTypes(stream);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
            for(int j=0; j < fileTypes.length; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
                returnTypesSet.add(fileTypes[j]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
        AudioFileFormat.Type returnTypes[] = (AudioFileFormat.Type[])
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
            returnTypesSet.toArray(new AudioFileFormat.Type[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
        return returnTypes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
     * Indicates whether an audio file of the specified file type can be written
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
     * from the indicated audio input stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
     * @param fileType the file type for which write capabilities are queried
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
     * @param stream the stream for which file-writing support is queried
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
     * @return <code>true</code> if the file type is supported for this audio input stream,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
     * otherwise <code>false</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
    public static boolean isFileTypeSupported(AudioFileFormat.Type fileType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
                                              AudioInputStream stream) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
        List providers = getAudioFileWriters();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
        for(int i=0; i < providers.size(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
            AudioFileWriter writer = (AudioFileWriter) providers.get(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
            if(writer.isFileTypeSupported(fileType, stream)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
     * Writes a stream of bytes representing an audio file of the specified file type
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
     * to the output stream provided.  Some file types require that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
     * the length be written into the file header; such files cannot be written from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
     * start to finish unless the length is known in advance.  An attempt
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
     * to write a file of such a type will fail with an IOException if the length in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
     * the audio file type is <code>AudioSystem.NOT_SPECIFIED</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
     * @param stream the audio input stream containing audio data to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
     * written to the file
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
     * @param fileType the kind of audio file to write
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
     * @param out the stream to which the file data should be written
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
     * @return the number of bytes written to the output stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
     * @throws IOException if an input/output exception occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
     * @throws IllegalArgumentException if the file type is not supported by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
     * the system
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
     * @see #isFileTypeSupported
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
     * @see     #getAudioFileTypes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
    public static int write(AudioInputStream stream, AudioFileFormat.Type fileType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
                            OutputStream out) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
        List providers = getAudioFileWriters();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
        int bytesWritten = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
        boolean flag = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
        for(int i=0; i < providers.size(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
            AudioFileWriter writer = (AudioFileWriter) providers.get(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
                bytesWritten = writer.write( stream, fileType, out ); // throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
                flag = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
            } catch (IllegalArgumentException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
                // thrown if this provider cannot write the sequence, try the next
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
        if(!flag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
            throw new IllegalArgumentException("could not write audio file: file type not supported: " + fileType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
            return bytesWritten;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
     * Writes a stream of bytes representing an audio file of the specified file type
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
     * to the external file provided.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
     * @param stream the audio input stream containing audio data to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
     * written to the file
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
     * @param fileType the kind of audio file to write
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
     * @param out the external file to which the file data should be written
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
     * @return the number of bytes written to the file
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
     * @throws IOException if an I/O exception occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
     * @throws IllegalArgumentException if the file type is not supported by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
     * the system
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
     * @see #isFileTypeSupported
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
     * @see     #getAudioFileTypes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
    public static int write(AudioInputStream stream, AudioFileFormat.Type fileType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
                            File out) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
        List providers = getAudioFileWriters();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
        int bytesWritten = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
        boolean flag = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
        for(int i=0; i < providers.size(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
            AudioFileWriter writer = (AudioFileWriter) providers.get(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
                bytesWritten = writer.write( stream, fileType, out ); // throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
                flag = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
            } catch (IllegalArgumentException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
                // thrown if this provider cannot write the sequence, try the next
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
        if (!flag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
            throw new IllegalArgumentException("could not write audio file: file type not supported: " + fileType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
            return bytesWritten;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
    // METHODS FOR INTERNAL IMPLEMENTATION USE
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
     * Obtains the set of MixerProviders on the system.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
    private static List getMixerProviders() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
        return getProviders(MixerProvider.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
     * Obtains the set of format converters (codecs, transcoders, etc.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
     * that are currently installed on the system.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
     * @return an array of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
     * {@link javax.sound.sampled.spi.FormatConversionProvider
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
     * FormatConversionProvider}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
     * objects representing the available format converters.  If no format
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
     * converters readers are available on the system, an array of length 0 is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
     * returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
    private static List getFormatConversionProviders() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
        return getProviders(FormatConversionProvider.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
     * Obtains the set of audio file readers that are currently installed on the system.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
     * @return a List of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
     * {@link javax.sound.sampled.spi.AudioFileReader
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
     * AudioFileReader}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
     * objects representing the installed audio file readers.  If no audio file
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
     * readers are available on the system, an empty List is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
    private static List getAudioFileReaders() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
        return getProviders(AudioFileReader.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
     * Obtains the set of audio file writers that are currently installed on the system.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
     * @return a List of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
     * {@link javax.sound.samples.spi.AudioFileWriter AudioFileWriter}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
     * objects representing the available audio file writers.  If no audio file
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
     * writers are available on the system, an empty List is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
    private static List getAudioFileWriters() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
        return getProviders(AudioFileWriter.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
    /** Attempts to locate and return a default Mixer that provides lines
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
     * of the specified type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
     * @param providers the installed mixer providers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
     * @param info The requested line type
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
     * TargetDataLine.class, Clip.class or Port.class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
     * @return a Mixer that matches the requirements, or null if no default mixer found
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
    private static Mixer getDefaultMixer(List providers, Line.Info info) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
        Class lineClass = info.getLineClass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
        String providerClassName = JDK13Services.getDefaultProviderClassName(lineClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
        String instanceName = JDK13Services.getDefaultInstanceName(lineClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
        Mixer mixer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
        if (providerClassName != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
            MixerProvider defaultProvider = getNamedProvider(providerClassName, providers);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
            if (defaultProvider != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
                if (instanceName != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
                    mixer = getNamedMixer(instanceName, defaultProvider, info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
                    if (mixer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
                        return mixer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
                    mixer = getFirstMixer(defaultProvider, info,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
                                          false /* mixing not required*/);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
                    if (mixer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
                        return mixer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
        /* Provider class not specified or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
           provider class cannot be found, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
           provider class and instance specified and instance cannot be found or is not appropriate */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
        if (instanceName != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
            mixer = getNamedMixer(instanceName, providers, info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
            if (mixer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
                return mixer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
        /* No default are specified, or if something is specified, everything
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
           failed. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
    /** Return a MixerProvider of a given class from the list of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
        MixerProviders.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
        This method never requires the returned Mixer to do mixing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
        @param providerClassName The class name of the provider to be returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
        @param providers The list of MixerProviders that is searched.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
        @return A MixerProvider of the requested class, or null if none is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
        found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
    private static MixerProvider getNamedProvider(String providerClassName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
                                                  List providers) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
        for(int i = 0; i < providers.size(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
            MixerProvider provider = (MixerProvider) providers.get(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
            if (provider.getClass().getName().equals(providerClassName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
                return provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
    /** Return a Mixer with a given name from a given MixerProvider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
      This method never requires the returned Mixer to do mixing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
      @param mixerName The name of the Mixer to be returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
      @param provider The MixerProvider to check for Mixers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
      @param info The type of line the returned Mixer is required to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
      support.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
      @return A Mixer matching the requirements, or null if none is found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
    private static Mixer getNamedMixer(String mixerName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
                                       MixerProvider provider,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
                                       Line.Info info) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
        Mixer.Info[] infos = provider.getMixerInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
        for (int i = 0; i < infos.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
            if (infos[i].getName().equals(mixerName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
                Mixer mixer = provider.getMixer(infos[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
                if (isAppropriateMixer(mixer, info, false)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
                    return mixer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
    /** From a List of MixerProviders, return a Mixer with a given name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
        This method never requires the returned Mixer to do mixing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
        @param mixerName The name of the Mixer to be returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
        @param providers The List of MixerProviders to check for Mixers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
        @param info The type of line the returned Mixer is required to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
        support.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
        @return A Mixer matching the requirements, or null if none is found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
    private static Mixer getNamedMixer(String mixerName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
                                       List providers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
                                       Line.Info info) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
        for(int i = 0; i < providers.size(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
            MixerProvider provider = (MixerProvider) providers.get(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
            Mixer mixer = getNamedMixer(mixerName, provider, info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
            if (mixer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
                return mixer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
    /** From a given MixerProvider, return the first appropriate Mixer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
        @param provider The MixerProvider to check for Mixers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
        @param info The type of line the returned Mixer is required to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
        support.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
        @param isMixingRequired If true, only Mixers that support mixing are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
        returned for line types of SourceDataLine and Clip.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
        @return A Mixer that is considered appropriate, or null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
        if none is found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
    private static Mixer getFirstMixer(MixerProvider provider,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
                                       Line.Info info,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
                                       boolean isMixingRequired) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
        Mixer.Info[] infos = provider.getMixerInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
        for (int j = 0; j < infos.length; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
            Mixer mixer = provider.getMixer(infos[j]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
            if (isAppropriateMixer(mixer, info, isMixingRequired)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
                return mixer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
    /** Checks if a Mixer is appropriate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
        A Mixer is considered appropriate if it support the given line type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
        If isMixingRequired is true and the line type is an output one
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
        (SourceDataLine, Clip), the mixer is appropriate if it supports
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
        at least 2 (concurrent) lines of the given type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
        @return true if the mixer is considered appropriate according to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
        rules given above, false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
    private static boolean isAppropriateMixer(Mixer mixer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
                                              Line.Info lineInfo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
                                              boolean isMixingRequired) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
        if (! mixer.isLineSupported(lineInfo)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
        Class lineClass = lineInfo.getLineClass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
        if (isMixingRequired
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
            && (SourceDataLine.class.isAssignableFrom(lineClass) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
                Clip.class.isAssignableFrom(lineClass))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
            int maxLines = mixer.getMaxLines(lineInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
            return ((maxLines == NOT_SPECIFIED) || (maxLines > 1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
     * Like getMixerInfo, but return List
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
    private static List getMixerInfoList() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
        List providers = getMixerProviders();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
        return getMixerInfoList(providers);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
     * Like getMixerInfo, but return List
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
    private static List getMixerInfoList(List providers) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
        List infos = new ArrayList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
        Mixer.Info[] someInfos; // per-mixer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
        Mixer.Info[] allInfos;  // for all mixers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
        for(int i = 0; i < providers.size(); i++ ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
            someInfos = (Mixer.Info[])
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
                ((MixerProvider)providers.get(i)).getMixerInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
            for (int j = 0; j < someInfos.length; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
                infos.add(someInfos[j]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
        return infos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
     * Obtains the set of services currently installed on the system
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
     * using sun.misc.Service, the SPI mechanism in 1.3.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
     * @return a List of instances of providers for the requested service.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
     * If no providers are available, a vector of length 0 will be returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
    private static List getProviders(Class providerClass) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
        return JDK13Services.getProviders(providerClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
}