1 7 8 package javax.sound.sampled; 9 10 import java.io.File ; 11 import java.io.InputStream ; 12 import java.io.IOException ; 13 import java.io.OutputStream ; 14 import java.net.URL ; 15 16 import java.util.HashSet ; 17 import java.util.List ; 18 import java.util.Set ; 19 import java.util.Vector ; 20 import java.util.ArrayList ; 21 22 import javax.sound.sampled.spi.AudioFileWriter ; 23 import javax.sound.sampled.spi.AudioFileReader ; 24 import javax.sound.sampled.spi.FormatConversionProvider ; 25 import javax.sound.sampled.spi.MixerProvider ; 26 27 import com.sun.media.sound.JDK13Services; 28 29 32 33 34 151 public class AudioSystem { 152 153 162 public static final int NOT_SPECIFIED = -1; 163 164 167 private AudioSystem() { 168 } 169 170 171 178 public static Mixer.Info [] getMixerInfo() { 179 180 List infos = getMixerInfoList(); 181 Mixer.Info [] allInfos = (Mixer.Info []) infos.toArray(new Mixer.Info [infos.size()]); 182 return allInfos; 183 } 184 185 186 197 public static Mixer getMixer(Mixer.Info info) { 198 199 Mixer mixer = null; 200 List providers = getMixerProviders(); 201 202 for(int i = 0; i < providers.size(); i++ ) { 203 204 try { 205 return ((MixerProvider )providers.get(i)).getMixer(info); 206 207 } catch (IllegalArgumentException e) { 208 } catch (NullPointerException e) { 209 } 216 } 217 218 if (info == null) { 220 for(int i = 0; i < providers.size(); i++ ) { 221 try { 222 MixerProvider provider = (MixerProvider ) providers.get(i); 223 Mixer.Info [] infos = provider.getMixerInfo(); 224 for (int ii = 0; ii < infos.length; ii++) { 226 try { 227 return provider.getMixer(infos[ii]); 228 } catch (IllegalArgumentException e) { 229 } 231 } 232 } catch (IllegalArgumentException e) { 233 } catch (NullPointerException e) { 234 } 235 } 236 } 237 238 239 throw new IllegalArgumentException ("Mixer not supported: " 240 + (info!=null?info.toString():"null")); 241 } 242 243 244 256 public static Line.Info [] getSourceLineInfo(Line.Info info) { 257 258 Vector vector = new Vector (); 259 Line.Info [] currentInfoArray; 260 261 Mixer mixer; 262 Line.Info fullInfo = null; 263 Mixer.Info [] infoArray = getMixerInfo(); 264 265 for (int i = 0; i < infoArray.length; i++) { 266 267 mixer = getMixer(infoArray[i]); 268 269 currentInfoArray = mixer.getSourceLineInfo(info); 270 for (int j = 0; j < currentInfoArray.length; j++) { 271 vector.addElement(currentInfoArray[j]); 272 } 273 } 274 275 Line.Info [] returnedArray = new Line.Info [vector.size()]; 276 277 for (int i = 0; i < returnedArray.length; i++) { 278 returnedArray[i] = (Line.Info )vector.get(i); 279 } 280 281 return returnedArray; 282 } 283 284 285 296 public static Line.Info [] getTargetLineInfo(Line.Info info) { 297 298 Vector vector = new Vector (); 299 Line.Info [] currentInfoArray; 300 301 Mixer mixer; 302 Line.Info fullInfo = null; 303 Mixer.Info [] infoArray = getMixerInfo(); 304 305 for (int i = 0; i < infoArray.length; i++) { 306 307 mixer = getMixer(infoArray[i]); 308 309 currentInfoArray = mixer.getTargetLineInfo(info); 310 for (int j = 0; j < currentInfoArray.length; j++) { 311 vector.addElement(currentInfoArray[j]); 312 } 313 } 314 315 Line.Info [] returnedArray = new Line.Info [vector.size()]; 316 317 for (int i = 0; i < returnedArray.length; i++) { 318 returnedArray[i] = (Line.Info )vector.get(i); 319 } 320 321 return returnedArray; 322 } 323 324 325 335 public static boolean isLineSupported(Line.Info info) { 336 337 Mixer mixer; 338 Mixer.Info [] infoArray = getMixerInfo(); 339 340 for (int i = 0; i < infoArray.length; i++) { 341 342 if( infoArray[i] != null ) { 343 mixer = getMixer(infoArray[i]); 344 if (mixer.isLineSupported(info)) { 345 return true; 346 } 347 } 348 } 349 350 return false; 351 } 352 353 390 public static Line getLine(Line.Info info) throws LineUnavailableException { 391 LineUnavailableException lue = null; 392 List providers = getMixerProviders(); 393 394 395 try { 397 Mixer mixer = getDefaultMixer(providers, info); 398 if (mixer != null && mixer.isLineSupported(info)) { 399 return mixer.getLine(info); 400 } 401 } catch (LineUnavailableException e) { 402 lue = e; 403 } catch (IllegalArgumentException iae) { 404 } 407 408 409 for(int i = 0; i < providers.size(); i++) { 411 MixerProvider provider = (MixerProvider ) providers.get(i); 412 Mixer.Info [] infos = provider.getMixerInfo(); 413 414 for (int j = 0; j < infos.length; j++) { 415 try { 416 Mixer mixer = provider.getMixer(infos[j]); 417 if (isAppropriateMixer(mixer, info, true)) { 419 return mixer.getLine(info); 420 } 421 } catch (LineUnavailableException e) { 422 lue = e; 423 } catch (IllegalArgumentException iae) { 424 } 427 } 428 } 429 430 431 for(int i = 0; i < providers.size(); i++) { 433 MixerProvider provider = (MixerProvider ) providers.get(i); 434 Mixer.Info [] infos = provider.getMixerInfo(); 435 for (int j = 0; j < infos.length; j++) { 436 try { 437 Mixer mixer = provider.getMixer(infos[j]); 438 if (isAppropriateMixer(mixer, info, false)) { 440 return mixer.getLine(info); 441 } 442 } catch (LineUnavailableException e) { 443 lue = e; 444 } catch (IllegalArgumentException iae) { 445 } 448 } 449 } 450 451 if (lue != null) { 454 throw lue; 455 } 456 457 throw new IllegalArgumentException ("No line matching " + 460 info.toString() + " is supported."); 461 } 462 463 464 497 public static Clip getClip() throws LineUnavailableException { 498 AudioFormat format = new AudioFormat (AudioFormat.Encoding.PCM_SIGNED, 499 AudioSystem.NOT_SPECIFIED, 500 16, 2, 4, 501 AudioSystem.NOT_SPECIFIED, true); 502 DataLine.Info info = new DataLine.Info (Clip .class, format); 503 return (Clip ) AudioSystem.getLine(info); 504 } 505 506 507 532 public static Clip getClip(Mixer.Info mixerInfo) throws LineUnavailableException { 533 AudioFormat format = new AudioFormat (AudioFormat.Encoding.PCM_SIGNED, 534 AudioSystem.NOT_SPECIFIED, 535 16, 2, 4, 536 AudioSystem.NOT_SPECIFIED, true); 537 DataLine.Info info = new DataLine.Info (Clip .class, format); 538 Mixer mixer = AudioSystem.getMixer(mixerInfo); 539 return (Clip ) mixer.getLine(info); 540 } 541 542 543 584 public static SourceDataLine getSourceDataLine(AudioFormat format) 585 throws LineUnavailableException { 586 DataLine.Info info = new DataLine.Info (SourceDataLine .class, format); 587 return (SourceDataLine ) AudioSystem.getLine(info); 588 } 589 590 591 628 public static SourceDataLine getSourceDataLine(AudioFormat format, 629 Mixer.Info mixerinfo) 630 throws LineUnavailableException { 631 DataLine.Info info = new DataLine.Info (SourceDataLine .class, format); 632 Mixer mixer = AudioSystem.getMixer(mixerinfo); 633 return (SourceDataLine ) mixer.getLine(info); 634 } 635 636 637 673 public static TargetDataLine getTargetDataLine(AudioFormat format) 674 throws LineUnavailableException { 675 676 DataLine.Info info = new DataLine.Info (TargetDataLine .class, format); 677 return (TargetDataLine ) AudioSystem.getLine(info); 678 } 679 680 681 682 725 public static TargetDataLine getTargetDataLine(AudioFormat format, 726 Mixer.Info mixerinfo) 727 throws LineUnavailableException { 728 729 DataLine.Info info = new DataLine.Info (TargetDataLine .class, format); 730 Mixer mixer = AudioSystem.getMixer(mixerinfo); 731 return (TargetDataLine ) mixer.getLine(info); 732 } 733 734 735 746 public static AudioFormat.Encoding [] getTargetEncodings(AudioFormat.Encoding sourceEncoding) { 747 748 List codecs = getFormatConversionProviders(); 749 Vector encodings = new Vector (); 750 751 AudioFormat.Encoding encs[] = null; 752 753 for(int i=0; i<codecs.size(); i++ ) { 755 FormatConversionProvider codec = (FormatConversionProvider ) codecs.get(i); 756 if( codec.isSourceEncodingSupported( sourceEncoding ) ) { 757 encs = codec.getTargetEncodings(); 758 for (int j = 0; j < encs.length; j++) { 759 encodings.addElement( encs[j] ); 760 } 761 } 762 } 763 AudioFormat.Encoding encs2[] = (AudioFormat.Encoding []) encodings.toArray(new AudioFormat.Encoding [0]); 764 return encs2; 765 } 766 767 768 769 780 public static AudioFormat.Encoding [] getTargetEncodings(AudioFormat sourceFormat) { 781 782 783 List codecs = getFormatConversionProviders(); 784 Vector encodings = new Vector (); 785 786 int size = 0; 787 int index = 0; 788 AudioFormat.Encoding encs[] = null; 789 790 792 for(int i=0; i<codecs.size(); i++ ) { 793 encs = ((FormatConversionProvider ) codecs.get(i)).getTargetEncodings(sourceFormat); 794 size += encs.length; 795 encodings.addElement( encs ); 796 } 797 798 800 AudioFormat.Encoding encs2[] = new AudioFormat.Encoding [size]; 801 for(int i=0; i<encodings.size(); i++ ) { 802 encs = (AudioFormat.Encoding [])(encodings.get(i)); 803 for(int j=0; j<encs.length; j++ ) { 804 encs2[index++] = encs[j]; 805 } 806 } 807 return encs2; 808 } 809 810 811 820 public static boolean isConversionSupported(AudioFormat.Encoding targetEncoding, AudioFormat sourceFormat) { 821 822 823 List codecs = getFormatConversionProviders(); 824 825 for(int i=0; i<codecs.size(); i++ ) { 826 FormatConversionProvider codec = (FormatConversionProvider ) codecs.get(i); 827 if(codec.isConversionSupported(targetEncoding,sourceFormat) ) { 828 return true; 829 } 830 } 831 return false; 832 } 833 834 835 847 public static AudioInputStream getAudioInputStream(AudioFormat.Encoding targetEncoding, 848 AudioInputStream sourceStream) { 849 850 List codecs = getFormatConversionProviders(); 851 852 for(int i = 0; i < codecs.size(); i++) { 853 FormatConversionProvider codec = (FormatConversionProvider ) codecs.get(i); 854 if( codec.isConversionSupported( targetEncoding, sourceStream.getFormat() ) ) { 855 return codec.getAudioInputStream( targetEncoding, sourceStream ); 856 } 857 } 858 throw new IllegalArgumentException ("Unsupported conversion: " + targetEncoding + " from " + sourceStream.getFormat()); 860 } 861 862 863 872 public static AudioFormat [] getTargetFormats(AudioFormat.Encoding targetEncoding, AudioFormat sourceFormat) { 873 874 List codecs = getFormatConversionProviders(); 875 Vector formats = new Vector (); 876 877 int size = 0; 878 int index = 0; 879 AudioFormat fmts[] = null; 880 881 883 for(int i=0; i<codecs.size(); i++ ) { 884 FormatConversionProvider codec = (FormatConversionProvider ) codecs.get(i); 885 fmts = codec.getTargetFormats(targetEncoding, sourceFormat); 886 size += fmts.length; 887 formats.addElement( fmts ); 888 } 889 890 892 AudioFormat fmts2[] = new AudioFormat [size]; 893 for(int i=0; i<formats.size(); i++ ) { 894 fmts = (AudioFormat [])(formats.get(i)); 895 for(int j=0; j<fmts.length; j++ ) { 896 fmts2[index++] = fmts[j]; 897 } 898 } 899 return fmts2; 900 } 901 902 903 911 912 public static boolean isConversionSupported(AudioFormat targetFormat, AudioFormat sourceFormat) { 913 914 List codecs = getFormatConversionProviders(); 915 916 for(int i=0; i<codecs.size(); i++ ) { 917 FormatConversionProvider codec = (FormatConversionProvider ) codecs.get(i); 918 if(codec.isConversionSupported(targetFormat, sourceFormat) ) { 919 return true; 920 } 921 } 922 return false; 923 } 924 925 926 938 public static AudioInputStream getAudioInputStream(AudioFormat targetFormat, 939 AudioInputStream sourceStream) { 940 941 if (sourceStream.getFormat().matches(targetFormat)) { 942 return sourceStream; 943 } 944 945 List codecs = getFormatConversionProviders(); 946 947 for(int i = 0; i < codecs.size(); i++) { 948 FormatConversionProvider codec = (FormatConversionProvider ) codecs.get(i); 949 if(codec.isConversionSupported(targetFormat,sourceStream.getFormat()) ) { 950 return codec.getAudioInputStream(targetFormat,sourceStream); 951 } 952 } 953 954 throw new IllegalArgumentException ("Unsupported conversion: " + targetFormat + " from " + sourceStream.getFormat()); 956 } 957 958 959 976 public static AudioFileFormat getAudioFileFormat(InputStream stream) 977 throws UnsupportedAudioFileException , IOException { 978 979 List providers = getAudioFileReaders(); 980 AudioFileFormat format = null; 981 982 for(int i = 0; i < providers.size(); i++ ) { 983 AudioFileReader reader = (AudioFileReader ) providers.get(i); 984 try { 985 format = reader.getAudioFileFormat( stream ); break; 987 } catch (UnsupportedAudioFileException e) { 988 continue; 989 } 990 } 991 992 if( format==null ) { 993 throw new UnsupportedAudioFileException ("file is not a supported file type"); 994 } else { 995 return format; 996 } 997 } 998 999 1009 public static AudioFileFormat getAudioFileFormat(URL url) 1010 throws UnsupportedAudioFileException , IOException { 1011 1012 List providers = getAudioFileReaders(); 1013 AudioFileFormat format = null; 1014 1015 for(int i = 0; i < providers.size(); i++ ) { 1016 AudioFileReader reader = (AudioFileReader ) providers.get(i); 1017 try { 1018 format = reader.getAudioFileFormat( url ); break; 1020 } catch (UnsupportedAudioFileException e) { 1021 continue; 1022 } 1023 } 1024 1025 if( format==null ) { 1026 throw new UnsupportedAudioFileException ("file is not a supported file type"); 1027 } else { 1028 return format; 1029 } 1030 } 1031 1032 1042 public static AudioFileFormat getAudioFileFormat(File file) 1043 throws UnsupportedAudioFileException , IOException { 1044 1045 List providers = getAudioFileReaders(); 1046 AudioFileFormat format = null; 1047 1048 for(int i = 0; i < providers.size(); i++ ) { 1049 AudioFileReader reader = (AudioFileReader ) providers.get(i); 1050 try { 1051 format = reader.getAudioFileFormat( file ); break; 1053 } catch (UnsupportedAudioFileException e) { 1054 continue; 1055 } 1056 } 1057 1058 if( format==null ) { 1059 throw new UnsupportedAudioFileException ("file is not a supported file type"); 1060 } else { 1061 return format; 1062 } 1063 } 1064 1065 1066 1085 public static AudioInputStream getAudioInputStream(InputStream stream) 1086 throws UnsupportedAudioFileException , IOException { 1087 1088 List providers = getAudioFileReaders(); 1089 AudioInputStream audioStream = null; 1090 1091 for(int i = 0; i < providers.size(); i++ ) { 1092 AudioFileReader reader = (AudioFileReader ) providers.get(i); 1093 try { 1094 audioStream = reader.getAudioInputStream( stream ); break; 1096 } catch (UnsupportedAudioFileException e) { 1097 continue; 1098 } 1099 } 1100 1101 if( audioStream==null ) { 1102 throw new UnsupportedAudioFileException ("could not get audio input stream from input stream"); 1103 } else { 1104 return audioStream; 1105 } 1106 } 1107 1108 1119 public static AudioInputStream getAudioInputStream(URL url) 1120 throws UnsupportedAudioFileException , IOException { 1121 1122 List providers = getAudioFileReaders(); 1123 AudioInputStream audioStream = null; 1124 1125 for(int i = 0; i < providers.size(); i++ ) { 1126 AudioFileReader reader = (AudioFileReader ) providers.get(i); 1127 try { 1128 audioStream = reader.getAudioInputStream( url ); break; 1130 } catch (UnsupportedAudioFileException e) { 1131 continue; 1132 } 1133 } 1134 1135 if( audioStream==null ) { 1136 throw new UnsupportedAudioFileException ("could not get audio input stream from input URL"); 1137 } else { 1138 return audioStream; 1139 } 1140 } 1141 1142 1153 public static AudioInputStream getAudioInputStream(File file) 1154 throws UnsupportedAudioFileException , IOException { 1155 1156 List providers = getAudioFileReaders(); 1157 AudioInputStream audioStream = null; 1158 1159 for(int i = 0; i < providers.size(); i++ ) { 1160 AudioFileReader reader = (AudioFileReader ) providers.get(i); 1161 try { 1162 audioStream = reader.getAudioInputStream( file ); break; 1164 } catch (UnsupportedAudioFileException e) { 1165 continue; 1166 } 1167 } 1168 1169 if( audioStream==null ) { 1170 throw new UnsupportedAudioFileException ("could not get audio input stream from input file"); 1171 } else { 1172 return audioStream; 1173 } 1174 } 1175 1176 1177 1182 public static AudioFileFormat.Type [] getAudioFileTypes() { 1183 List providers = getAudioFileWriters(); 1184 Set returnTypesSet = new HashSet (); 1185 1186 for(int i=0; i < providers.size(); i++) { 1187 AudioFileWriter writer = (AudioFileWriter ) providers.get(i); 1188 AudioFileFormat.Type [] fileTypes = writer.getAudioFileTypes(); 1189 for(int j=0; j < fileTypes.length; j++) { 1190 returnTypesSet.add(fileTypes[j]); 1191 } 1192 } 1193 AudioFileFormat.Type returnTypes[] = (AudioFileFormat.Type []) 1194 returnTypesSet.toArray(new AudioFileFormat.Type [0]); 1195 return returnTypes; 1196 } 1197 1198 1199 1206 public static boolean isFileTypeSupported(AudioFileFormat.Type fileType) { 1207 1208 List providers = getAudioFileWriters(); 1209 1210 for(int i=0; i < providers.size(); i++) { 1211 AudioFileWriter writer = (AudioFileWriter ) providers.get(i); 1212 if (writer.isFileTypeSupported(fileType)) { 1213 return true; 1214 } 1215 } 1216 return false; 1217 } 1218 1219 1220 1228 public static AudioFileFormat.Type [] getAudioFileTypes(AudioInputStream stream) { 1229 List providers = getAudioFileWriters(); 1230 Set returnTypesSet = new HashSet (); 1231 1232 for(int i=0; i < providers.size(); i++) { 1233 AudioFileWriter writer = (AudioFileWriter ) providers.get(i); 1234 AudioFileFormat.Type [] fileTypes = writer.getAudioFileTypes(stream); 1235 for(int j=0; j < fileTypes.length; j++) { 1236 returnTypesSet.add(fileTypes[j]); 1237 } 1238 } 1239 AudioFileFormat.Type returnTypes[] = (AudioFileFormat.Type []) 1240 returnTypesSet.toArray(new AudioFileFormat.Type [0]); 1241 return returnTypes; 1242 } 1243 1244 1245 1253 public static boolean isFileTypeSupported(AudioFileFormat.Type fileType, 1254 AudioInputStream stream) { 1255 1256 List providers = getAudioFileWriters(); 1257 1258 for(int i=0; i < providers.size(); i++) { 1259 AudioFileWriter writer = (AudioFileWriter ) providers.get(i); 1260 if(writer.isFileTypeSupported(fileType, stream)) { 1261 return true; 1262 } 1263 } 1264 return false; 1265 } 1266 1267 1268 1287 public static int write(AudioInputStream stream, AudioFileFormat.Type fileType, 1288 OutputStream out) throws IOException { 1289 1290 List providers = getAudioFileWriters(); 1291 int bytesWritten = 0; 1292 boolean flag = false; 1293 1294 for(int i=0; i < providers.size(); i++) { 1295 AudioFileWriter writer = (AudioFileWriter ) providers.get(i); 1296 try { 1297 bytesWritten = writer.write( stream, fileType, out ); flag = true; 1299 break; 1300 } catch (IllegalArgumentException e) { 1301 continue; 1303 } 1304 } 1305 if(!flag) { 1306 throw new IllegalArgumentException ("could not write audio file: file type not supported: " + fileType); 1307 } else { 1308 return bytesWritten; 1309 } 1310 } 1311 1312 1313 1327 public static int write(AudioInputStream stream, AudioFileFormat.Type fileType, 1328 File out) throws IOException { 1329 1330 List providers = getAudioFileWriters(); 1331 int bytesWritten = 0; 1332 boolean flag = false; 1333 1334 for(int i=0; i < providers.size(); i++) { 1335 AudioFileWriter writer = (AudioFileWriter ) providers.get(i); 1336 try { 1337 bytesWritten = writer.write( stream, fileType, out ); flag = true; 1339 break; 1340 } catch (IllegalArgumentException e) { 1341 continue; 1343 } 1344 } 1345 if (!flag) { 1346 throw new IllegalArgumentException ("could not write audio file: file type not supported: " + fileType); 1347 } else { 1348 return bytesWritten; 1349 } 1350 } 1351 1352 1353 1355 1358 private static List getMixerProviders() { 1359 return getProviders(MixerProvider .class); 1360 } 1361 1362 1363 1373 private static List getFormatConversionProviders() { 1374 return getProviders(FormatConversionProvider .class); 1375 } 1376 1377 1378 1386 private static List getAudioFileReaders() { 1387 return getProviders(AudioFileReader .class); 1388 } 1389 1390 1391 1398 private static List getAudioFileWriters() { 1399 return getProviders(AudioFileWriter .class); 1400 } 1401 1402 1403 1404 1412 private static Mixer getDefaultMixer(List providers, Line.Info info) { 1413 Class lineClass = info.getLineClass(); 1414 String providerClassName = JDK13Services.getDefaultProviderClassName(lineClass); 1415 String instanceName = JDK13Services.getDefaultInstanceName(lineClass); 1416 Mixer mixer; 1417 1418 if (providerClassName != null) { 1419 MixerProvider defaultProvider = getNamedProvider(providerClassName, providers); 1420 if (defaultProvider != null) { 1421 if (instanceName != null) { 1422 mixer = getNamedMixer(instanceName, defaultProvider, info); 1423 if (mixer != null) { 1424 return mixer; 1425 } 1426 } else { 1427 mixer = getFirstMixer(defaultProvider, info, 1428 false ); 1429 if (mixer != null) { 1430 return mixer; 1431 } 1432 } 1433 1434 } 1435 } 1436 1437 1440 if (instanceName != null) { 1441 mixer = getNamedMixer(instanceName, providers, info); 1442 if (mixer != null) { 1443 return mixer; 1444 } 1445 } 1446 1447 1448 1450 return null; 1451 } 1452 1453 1454 1455 1464 private static MixerProvider getNamedProvider(String providerClassName, 1465 List providers) { 1466 for(int i = 0; i < providers.size(); i++) { 1467 MixerProvider provider = (MixerProvider ) providers.get(i); 1468 if (provider.getClass().getName().equals(providerClassName)) { 1469 return provider; 1470 } 1471 } 1472 return null; 1473 } 1474 1475 1476 1485 private static Mixer getNamedMixer(String mixerName, 1486 MixerProvider provider, 1487 Line.Info info) { 1488 Mixer.Info [] infos = provider.getMixerInfo(); 1489 for (int i = 0; i < infos.length; i++) { 1490 if (infos[i].getName().equals(mixerName)) { 1491 Mixer mixer = provider.getMixer(infos[i]); 1492 if (isAppropriateMixer(mixer, info, false)) { 1493 return mixer; 1494 } 1495 } 1496 } 1497 return null; 1498 } 1499 1500 1501 1509 private static Mixer getNamedMixer(String mixerName, 1510 List providers, 1511 Line.Info info) { 1512 for(int i = 0; i < providers.size(); i++) { 1513 MixerProvider provider = (MixerProvider ) providers.get(i); 1514 Mixer mixer = getNamedMixer(mixerName, provider, info); 1515 if (mixer != null) { 1516 return mixer; 1517 } 1518 } 1519 return null; 1520 } 1521 1522 1523 1533 private static Mixer getFirstMixer(MixerProvider provider, 1534 Line.Info info, 1535 boolean isMixingRequired) { 1536 Mixer.Info [] infos = provider.getMixerInfo(); 1537 for (int j = 0; j < infos.length; j++) { 1538 Mixer mixer = provider.getMixer(infos[j]); 1539 if (isAppropriateMixer(mixer, info, isMixingRequired)) { 1540 return mixer; 1541 } 1542 } 1543 return null; 1544 } 1545 1546 1547 1556 private static boolean isAppropriateMixer(Mixer mixer, 1557 Line.Info lineInfo, 1558 boolean isMixingRequired) { 1559 if (! mixer.isLineSupported(lineInfo)) { 1560 return false; 1561 } 1562 Class lineClass = lineInfo.getLineClass(); 1563 if (isMixingRequired 1564 && (SourceDataLine .class.isAssignableFrom(lineClass) || 1565 Clip .class.isAssignableFrom(lineClass))) { 1566 int maxLines = mixer.getMaxLines(lineInfo); 1567 return ((maxLines == NOT_SPECIFIED) || (maxLines > 1)); 1568 } 1569 return true; 1570 } 1571 1572 1573 1574 1577 private static List getMixerInfoList() { 1578 List providers = getMixerProviders(); 1579 return getMixerInfoList(providers); 1580 } 1581 1582 1583 1586 private static List getMixerInfoList(List providers) { 1587 List infos = new ArrayList (); 1588 1589 Mixer.Info [] someInfos; Mixer.Info [] allInfos; 1592 for(int i = 0; i < providers.size(); i++ ) { 1593 someInfos = (Mixer.Info []) 1594 ((MixerProvider )providers.get(i)).getMixerInfo(); 1595 1596 for (int j = 0; j < someInfos.length; j++) { 1597 infos.add(someInfos[j]); 1598 } 1599 } 1600 1601 return infos; 1602 } 1603 1604 1605 1611 private static List getProviders(Class providerClass) { 1612 return JDK13Services.getProviders(providerClass); 1613 } 1614} 1615 | Popular Tags |