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