javax.sound.sampled.UnsupportedAudioFileException Java Examples
The following examples show how to use
javax.sound.sampled.UnsupportedAudioFileException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MetronomePlugin.java From plugins with GNU General Public License v3.0 | 8 votes |
private Clip GetAudioClip(String path) { File audioFile = new File(path); if (!audioFile.exists()) { return null; } try (AudioInputStream audioStream = AudioSystem.getAudioInputStream(audioFile)) { Clip audioClip = AudioSystem.getClip(); audioClip.open(audioStream); FloatControl gainControl = (FloatControl) audioClip.getControl(FloatControl.Type.MASTER_GAIN); float gainValue = (((float) config.volume()) * 40f / 100f) - 35f; gainControl.setValue(gainValue); return audioClip; } catch (IOException | LineUnavailableException | UnsupportedAudioFileException e) { log.warn("Error opening audiostream from " + audioFile, e); return null; } }
Example #2
Source File: WaveFloatFileReader.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
public AudioInputStream getAudioInputStream(InputStream stream) throws UnsupportedAudioFileException, IOException { AudioFileFormat format = getAudioFileFormat(stream); RIFFReader riffiterator = new RIFFReader(stream); if (!riffiterator.getFormat().equals("RIFF")) throw new UnsupportedAudioFileException(); if (!riffiterator.getType().equals("WAVE")) throw new UnsupportedAudioFileException(); while (riffiterator.hasNextChunk()) { RIFFReader chunk = riffiterator.nextChunk(); if (chunk.getFormat().equals("data")) { return new AudioInputStream(chunk, format.getFormat(), chunk.getSize()); } } throw new UnsupportedAudioFileException(); }
Example #3
Source File: AudioFileSoundbankReader.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
public Soundbank getSoundbank(File file) throws InvalidMidiDataException, IOException { try { AudioInputStream ais = AudioSystem.getAudioInputStream(file); ais.close(); ModelByteBufferWavetable osc = new ModelByteBufferWavetable( new ModelByteBuffer(file, 0, file.length()), -4800); ModelPerformer performer = new ModelPerformer(); performer.getOscillators().add(osc); SimpleSoundbank sbk = new SimpleSoundbank(); SimpleInstrument ins = new SimpleInstrument(); ins.add(performer); sbk.addInstrument(ins); return sbk; } catch (UnsupportedAudioFileException e1) { return null; } catch (IOException e) { return null; } }
Example #4
Source File: AiffFileReader.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
/** * Obtains an audio stream from the File provided. The File must * point to valid audio file data. * @param file the File for which the <code>AudioInputStream</code> should be * constructed * @return an <code>AudioInputStream</code> object based on the audio file data pointed * to by the File * @throws UnsupportedAudioFileException if the File does not point to valid audio * file data recognized by the system * @throws IOException if an I/O exception occurs */ public AudioInputStream getAudioInputStream(File file) throws UnsupportedAudioFileException, IOException { FileInputStream fis = new FileInputStream(file); // throws IOException AudioFileFormat fileFormat = null; // part of fix for 4325421 try { fileFormat = getCOMM(fis, false); } finally { if (fileFormat == null) { fis.close(); } } return new AudioInputStream(fis, fileFormat.getFormat(), fileFormat.getFrameLength()); }
Example #5
Source File: WaveFloatFileReader.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
public AudioInputStream getAudioInputStream(InputStream stream) throws UnsupportedAudioFileException, IOException { AudioFileFormat format = getAudioFileFormat(stream); RIFFReader riffiterator = new RIFFReader(stream); if (!riffiterator.getFormat().equals("RIFF")) throw new UnsupportedAudioFileException(); if (!riffiterator.getType().equals("WAVE")) throw new UnsupportedAudioFileException(); while (riffiterator.hasNextChunk()) { RIFFReader chunk = riffiterator.nextChunk(); if (chunk.getFormat().equals("data")) { return new AudioInputStream(chunk, format.getFormat(), chunk.getSize()); } } throw new UnsupportedAudioFileException(); }
Example #6
Source File: AudioFileSoundbankReader.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
public Soundbank getSoundbank(File file) throws InvalidMidiDataException, IOException { try { AudioInputStream ais = AudioSystem.getAudioInputStream(file); ais.close(); ModelByteBufferWavetable osc = new ModelByteBufferWavetable( new ModelByteBuffer(file, 0, file.length()), -4800); ModelPerformer performer = new ModelPerformer(); performer.getOscillators().add(osc); SimpleSoundbank sbk = new SimpleSoundbank(); SimpleInstrument ins = new SimpleInstrument(); ins.add(performer); sbk.addInstrument(ins); return sbk; } catch (UnsupportedAudioFileException e1) { return null; } catch (IOException e) { return null; } }
Example #7
Source File: AiffFileReader.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
/** * Obtains an audio stream from the File provided. The File must * point to valid audio file data. * @param file the File for which the <code>AudioInputStream</code> should be * constructed * @return an <code>AudioInputStream</code> object based on the audio file data pointed * to by the File * @throws UnsupportedAudioFileException if the File does not point to valid audio * file data recognized by the system * @throws IOException if an I/O exception occurs */ public AudioInputStream getAudioInputStream(File file) throws UnsupportedAudioFileException, IOException { FileInputStream fis = new FileInputStream(file); // throws IOException AudioFileFormat fileFormat = null; // part of fix for 4325421 try { fileFormat = getCOMM(fis, false); } finally { if (fileFormat == null) { fis.close(); } } return new AudioInputStream(fis, fileFormat.getFormat(), fileFormat.getFrameLength()); }
Example #8
Source File: WaveExtensibleFileReader.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
public AudioInputStream getAudioInputStream(InputStream stream) throws UnsupportedAudioFileException, IOException { AudioFileFormat format = getAudioFileFormat(stream); RIFFReader riffiterator = new RIFFReader(stream); if (!riffiterator.getFormat().equals("RIFF")) throw new UnsupportedAudioFileException(); if (!riffiterator.getType().equals("WAVE")) throw new UnsupportedAudioFileException(); while (riffiterator.hasNextChunk()) { RIFFReader chunk = riffiterator.nextChunk(); if (chunk.getFormat().equals("data")) { return new AudioInputStream(chunk, format.getFormat(), chunk .getSize()); } } throw new UnsupportedAudioFileException(); }
Example #9
Source File: WaveFileReader.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** * Obtains an audio stream from the URL provided. The URL must * point to valid audio file data. * @param url the URL for which the <code>AudioInputStream</code> should be * constructed * @return an <code>AudioInputStream</code> object based on the audio file data pointed * to by the URL * @throws UnsupportedAudioFileException if the URL does not point to valid audio * file data recognized by the system * @throws IOException if an I/O exception occurs */ public AudioInputStream getAudioInputStream(URL url) throws UnsupportedAudioFileException, IOException { InputStream urlStream = url.openStream(); // throws IOException AudioFileFormat fileFormat = null; try { fileFormat = getFMT(urlStream, false); } finally { if (fileFormat == null) { urlStream.close(); } } return new AudioInputStream(urlStream, fileFormat.getFormat(), fileFormat.getFrameLength()); }
Example #10
Source File: AiffFileReader.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** * Obtains the audio file format of the File provided. The File must * point to valid audio file data. * @param file the File from which file format information should be * extracted * @return an <code>AudioFileFormat</code> object describing the audio file format * @throws UnsupportedAudioFileException if the File does not point to valid audio * file data recognized by the system * @throws IOException if an I/O exception occurs */ public AudioFileFormat getAudioFileFormat(File file) throws UnsupportedAudioFileException, IOException { AudioFileFormat fileFormat = null; FileInputStream fis = new FileInputStream(file); // throws IOException // part of fix for 4325421 try { fileFormat = getCOMM(fis, false); } finally { fis.close(); } return fileFormat; }
Example #11
Source File: WaveFileReader.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** * Obtains an audio stream from the File provided. The File must * point to valid audio file data. * @param file the File for which the <code>AudioInputStream</code> should be * constructed * @return an <code>AudioInputStream</code> object based on the audio file data pointed * to by the File * @throws UnsupportedAudioFileException if the File does not point to valid audio * file data recognized by the system * @throws IOException if an I/O exception occurs */ public AudioInputStream getAudioInputStream(File file) throws UnsupportedAudioFileException, IOException { FileInputStream fis = new FileInputStream(file); // throws IOException AudioFileFormat fileFormat = null; // part of fix for 4325421 try { fileFormat = getFMT(fis, false); } finally { if (fileFormat == null) { fis.close(); } } return new AudioInputStream(fis, fileFormat.getFormat(), fileFormat.getFrameLength()); }
Example #12
Source File: WaveFloatFileReader.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
public AudioFileFormat getAudioFileFormat(InputStream stream) throws UnsupportedAudioFileException, IOException { stream.mark(200); AudioFileFormat format; try { format = internal_getAudioFileFormat(stream); } finally { stream.reset(); } return format; }
Example #13
Source File: WaveFloatFileReader.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
public AudioFileFormat getAudioFileFormat(File file) throws UnsupportedAudioFileException, IOException { InputStream stream = new FileInputStream(file); AudioFileFormat format; try { format = getAudioFileFormat(new BufferedInputStream(stream)); } finally { stream.close(); } return format; }
Example #14
Source File: JavaSoundAudioClip.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
public JavaSoundAudioClip(InputStream in) throws IOException { if (DEBUG || Printer.debug)Printer.debug("JavaSoundAudioClip.<init>"); BufferedInputStream bis = new BufferedInputStream(in, STREAM_BUFFER_SIZE); bis.mark(STREAM_BUFFER_SIZE); boolean success = false; try { AudioInputStream as = AudioSystem.getAudioInputStream(bis); // load the stream data into memory success = loadAudioData(as); if (success) { success = false; if (loadedAudioByteLength < CLIP_THRESHOLD) { success = createClip(); } if (!success) { success = createSourceDataLine(); } } } catch (UnsupportedAudioFileException e) { // not an audio file try { MidiFileFormat mff = MidiSystem.getMidiFileFormat(bis); success = createSequencer(bis); } catch (InvalidMidiDataException e1) { success = false; } } if (!success) { throw new IOException("Unable to create AudioClip from input stream"); } }
Example #15
Source File: AiffFileReader.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
/** * Obtains an audio stream from the URL provided. The URL must * point to valid audio file data. * @param url the URL for which the <code>AudioInputStream</code> should be * constructed * @return an <code>AudioInputStream</code> object based on the audio file data pointed * to by the URL * @throws UnsupportedAudioFileException if the URL does not point to valid audio * file data recognized by the system * @throws IOException if an I/O exception occurs */ public AudioInputStream getAudioInputStream(URL url) throws UnsupportedAudioFileException, IOException { InputStream urlStream = url.openStream(); // throws IOException AudioFileFormat fileFormat = null; try { fileFormat = getCOMM(urlStream, false); } finally { if (fileFormat == null) { urlStream.close(); } } return new AudioInputStream(urlStream, fileFormat.getFormat(), fileFormat.getFrameLength()); }
Example #16
Source File: AiffFileReader.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
/** * Obtains the audio file format of the File provided. The File must * point to valid audio file data. * @param file the File from which file format information should be * extracted * @return an <code>AudioFileFormat</code> object describing the audio file format * @throws UnsupportedAudioFileException if the File does not point to valid audio * file data recognized by the system * @throws IOException if an I/O exception occurs */ public AudioFileFormat getAudioFileFormat(File file) throws UnsupportedAudioFileException, IOException { AudioFileFormat fileFormat = null; FileInputStream fis = new FileInputStream(file); // throws IOException // part of fix for 4325421 try { fileFormat = getCOMM(fis, false); } finally { fis.close(); } return fileFormat; }
Example #17
Source File: WaveFloatFileReader.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
public AudioFileFormat getAudioFileFormat(URL url) throws UnsupportedAudioFileException, IOException { InputStream stream = url.openStream(); AudioFileFormat format; try { format = getAudioFileFormat(new BufferedInputStream(stream)); } finally { stream.close(); } return format; }
Example #18
Source File: AiffFileReader.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** * Obtains an audio stream from the URL provided. The URL must * point to valid audio file data. * @param url the URL for which the <code>AudioInputStream</code> should be * constructed * @return an <code>AudioInputStream</code> object based on the audio file data pointed * to by the URL * @throws UnsupportedAudioFileException if the URL does not point to valid audio * file data recognized by the system * @throws IOException if an I/O exception occurs */ public AudioInputStream getAudioInputStream(URL url) throws UnsupportedAudioFileException, IOException { InputStream urlStream = url.openStream(); // throws IOException AudioFileFormat fileFormat = null; try { fileFormat = getCOMM(urlStream, false); } finally { if (fileFormat == null) { urlStream.close(); } } return new AudioInputStream(urlStream, fileFormat.getFormat(), fileFormat.getFrameLength()); }
Example #19
Source File: WaveFileReader.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
/** * Obtains an audio stream from the URL provided. The URL must * point to valid audio file data. * @param url the URL for which the <code>AudioInputStream</code> should be * constructed * @return an <code>AudioInputStream</code> object based on the audio file data pointed * to by the URL * @throws UnsupportedAudioFileException if the URL does not point to valid audio * file data recognized by the system * @throws IOException if an I/O exception occurs */ public AudioInputStream getAudioInputStream(URL url) throws UnsupportedAudioFileException, IOException { InputStream urlStream = url.openStream(); // throws IOException AudioFileFormat fileFormat = null; try { fileFormat = getFMT(urlStream, false); } finally { if (fileFormat == null) { urlStream.close(); } } return new AudioInputStream(urlStream, fileFormat.getFormat(), fileFormat.getFrameLength()); }
Example #20
Source File: WaveFloatFileReader.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
public AudioFileFormat getAudioFileFormat(URL url) throws UnsupportedAudioFileException, IOException { InputStream stream = url.openStream(); AudioFileFormat format; try { format = getAudioFileFormat(new BufferedInputStream(stream)); } finally { stream.close(); } return format; }
Example #21
Source File: WaveFloatFileReader.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
public AudioFileFormat getAudioFileFormat(File file) throws UnsupportedAudioFileException, IOException { InputStream stream = new FileInputStream(file); AudioFileFormat format; try { format = getAudioFileFormat(new BufferedInputStream(stream)); } finally { stream.close(); } return format; }
Example #22
Source File: WaveFileReader.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** * Obtains the audio file format of the URL provided. The URL must * point to valid audio file data. * @param url the URL from which file format information should be * extracted * @return an <code>AudioFileFormat</code> object describing the audio file format * @throws UnsupportedAudioFileException if the URL does not point to valid audio * file data recognized by the system * @throws IOException if an I/O exception occurs */ public AudioFileFormat getAudioFileFormat(URL url) throws UnsupportedAudioFileException, IOException { InputStream urlStream = url.openStream(); // throws IOException AudioFileFormat fileFormat = null; try { fileFormat = getFMT(urlStream, false); } finally { urlStream.close(); } return fileFormat; }
Example #23
Source File: WaveExtensibleFileReader.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
public AudioFileFormat getAudioFileFormat(File file) throws UnsupportedAudioFileException, IOException { InputStream stream = new FileInputStream(file); AudioFileFormat format; try { format = getAudioFileFormat(new BufferedInputStream(stream)); } finally { stream.close(); } return format; }
Example #24
Source File: WaveExtensibleFileReader.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
public AudioFileFormat getAudioFileFormat(InputStream stream) throws UnsupportedAudioFileException, IOException { stream.mark(200); AudioFileFormat format; try { format = internal_getAudioFileFormat(stream); } finally { stream.reset(); } return format; }
Example #25
Source File: WaveExtensibleFileReader.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
public AudioFileFormat getAudioFileFormat(URL url) throws UnsupportedAudioFileException, IOException { InputStream stream = url.openStream(); AudioFileFormat format; try { format = getAudioFileFormat(new BufferedInputStream(stream)); } finally { stream.close(); } return format; }
Example #26
Source File: WaveExtensibleFileReader.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
public AudioFileFormat getAudioFileFormat(File file) throws UnsupportedAudioFileException, IOException { InputStream stream = new FileInputStream(file); AudioFileFormat format; try { format = getAudioFileFormat(new BufferedInputStream(stream)); } finally { stream.close(); } return format; }
Example #27
Source File: JavaSoundAudioClip.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
private boolean loadAudioData(AudioInputStream as) throws IOException, UnsupportedAudioFileException { if (DEBUG || Printer.debug)Printer.debug("JavaSoundAudioClip->openAsClip()"); // first possibly convert this stream to PCM as = Toolkit.getPCMConvertedAudioInputStream(as); if (as == null) { return false; } loadedAudioFormat = as.getFormat(); long frameLen = as.getFrameLength(); int frameSize = loadedAudioFormat.getFrameSize(); long byteLen = AudioSystem.NOT_SPECIFIED; if (frameLen != AudioSystem.NOT_SPECIFIED && frameLen > 0 && frameSize != AudioSystem.NOT_SPECIFIED && frameSize > 0) { byteLen = frameLen * frameSize; } if (byteLen != AudioSystem.NOT_SPECIFIED) { // if the stream length is known, it can be efficiently loaded into memory readStream(as, byteLen); } else { // otherwise we use a ByteArrayOutputStream to load it into memory readStream(as); } // if everything went fine, we have now the audio data in // loadedAudio, and the byte length in loadedAudioByteLength return true; }
Example #28
Source File: JavaSoundAudioClip.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
public JavaSoundAudioClip(InputStream in) throws IOException { if (DEBUG || Printer.debug)Printer.debug("JavaSoundAudioClip.<init>"); BufferedInputStream bis = new BufferedInputStream(in, STREAM_BUFFER_SIZE); bis.mark(STREAM_BUFFER_SIZE); boolean success = false; try { AudioInputStream as = AudioSystem.getAudioInputStream(bis); // load the stream data into memory success = loadAudioData(as); if (success) { success = false; if (loadedAudioByteLength < CLIP_THRESHOLD) { success = createClip(); } if (!success) { success = createSourceDataLine(); } } } catch (UnsupportedAudioFileException e) { // not an audio file try { MidiFileFormat mff = MidiSystem.getMidiFileFormat(bis); success = createSequencer(bis); } catch (InvalidMidiDataException e1) { success = false; } } if (!success) { throw new IOException("Unable to create AudioClip from input stream"); } }
Example #29
Source File: ReadersExceptions.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
private static void test(final byte[] buffer) throws IOException { final InputStream is = new ByteArrayInputStream(buffer); try { AudioSystem.getAudioFileFormat(is); } catch (UnsupportedAudioFileException ignored) { // Expected. return; } throw new RuntimeException("Test Failed"); }
Example #30
Source File: JavaSoundAudioClip.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
private boolean loadAudioData(AudioInputStream as) throws IOException, UnsupportedAudioFileException { if (DEBUG || Printer.debug)Printer.debug("JavaSoundAudioClip->openAsClip()"); // first possibly convert this stream to PCM as = Toolkit.getPCMConvertedAudioInputStream(as); if (as == null) { return false; } loadedAudioFormat = as.getFormat(); long frameLen = as.getFrameLength(); int frameSize = loadedAudioFormat.getFrameSize(); long byteLen = AudioSystem.NOT_SPECIFIED; if (frameLen != AudioSystem.NOT_SPECIFIED && frameLen > 0 && frameSize != AudioSystem.NOT_SPECIFIED && frameSize > 0) { byteLen = frameLen * frameSize; } if (byteLen != AudioSystem.NOT_SPECIFIED) { // if the stream length is known, it can be efficiently loaded into memory readStream(as, byteLen); } else { // otherwise we use a ByteArrayOutputStream to load it into memory readStream(as); } // if everything went fine, we have now the audio data in // loadedAudio, and the byte length in loadedAudioByteLength return true; }