List of usage examples for javax.sound.sampled AudioSystem getAudioFileTypes
public static AudioFileFormat.Type[] getAudioFileTypes()
From source file:it.univpm.deit.semedia.musicuri.core.Toolset.java
/** * Reports if the given audio file is supported by the current configuration of the host system. * Support for various audio file types depends on if the respective plugins have been installed." * @param file the file to check//from w ww . j a va 2 s . c o m * @return true if the filename ends with a ".wav" or ".mp3"extension, false otherwise */ public static boolean isSupportedAudioFile(File file) { // if ( isWAVFile(file) || isMP3File(file) ) return true; // else return false; boolean supported = false; String fname = file.getName(); String extension = fname.substring(fname.lastIndexOf('.') + 1); // get all audio formats supported by host system confifuration AudioFileFormat.Type[] supportedAudioFileTypes = AudioSystem.getAudioFileTypes(); for (int i = 0; i < supportedAudioFileTypes.length; i++) { if (extension.equalsIgnoreCase(supportedAudioFileTypes[i].getExtension())) return true; } return supported; }
From source file:org.snitko.app.record.SoundRecorder.java
public AudioInputStream record(long durationInSeconds) throws LineUnavailableException { Mixer.Info[] mixers = AudioSystem.getMixerInfo(); for (Mixer.Info mixer : mixers) { System.out.printf("mixer name/desc/vendor/version: %s, %s, %s, %s\n", mixer.getName(), mixer.getDescription(), mixer.getVendor(), mixer.getVersion()); }/*from w w w . ja va 2s . c o m*/ AudioFileFormat.Type[] types = AudioSystem.getAudioFileTypes(); for (AudioFileFormat.Type type : types) { System.out.println("audio types are: " + type.toString()); } AudioFormat audioFormat = getAudioFormat(); // the targetDataLine from which audio data is captured TargetDataLine targetDataLine = AudioSystem.getTargetDataLine(audioFormat); System.out.println("targetDataLine: " + targetDataLine + "\n\tlineInfo" + targetDataLine.getLineInfo() + "\n\tformat: " + targetDataLine.getFormat()); // checks if system supports the data targetDataLine if (!AudioSystem.isLineSupported(targetDataLine.getLineInfo())) { System.out.println("Line not supported"); System.exit(0); } targetDataLine.addLineListener(new TimedLineListener(targetDataLine, durationInSeconds)); targetDataLine.open(audioFormat); targetDataLine.start(); // start capturing System.out.println("Start capturing..."); AudioInputStream audioInputStream = new AudioInputStream(targetDataLine); System.out.println("Start recording..."); return audioInputStream; }