类javax.sound.sampled.UnsupportedAudioFileException源码实例Demo

下面列出了怎么用javax.sound.sampled.UnsupportedAudioFileException的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: plugins   文件: MetronomePlugin.java
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;
	}
}
 
源代码2 项目: dragonwell8_jdk   文件: AiffFileReader.java
/**
 * 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());
}
 
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;
    }
}
 
源代码4 项目: dragonwell8_jdk   文件: WaveFloatFileReader.java
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();
}
 
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();
}
 
源代码6 项目: TencentKona-8   文件: AiffFileReader.java
/**
 * 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());
}
 
源代码7 项目: TencentKona-8   文件: AudioFileSoundbankReader.java
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;
    }
}
 
源代码8 项目: TencentKona-8   文件: WaveFloatFileReader.java
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();
}
 
源代码9 项目: dragonwell8_jdk   文件: JavaSoundAudioClip.java
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");
    }
}
 
源代码10 项目: dragonwell8_jdk   文件: JavaSoundAudioClip.java
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;
}
 
源代码11 项目: dragonwell8_jdk   文件: WaveFileReader.java
/**
 * 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;
}
 
源代码12 项目: dragonwell8_jdk   文件: WaveFileReader.java
/**
 * 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 = getFMT(fis, false);
    } finally {
        fis.close();
    }

    return fileFormat;
}
 
源代码13 项目: dragonwell8_jdk   文件: WaveFileReader.java
/**
 * 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());
}
 
源代码14 项目: dragonwell8_jdk   文件: WaveFileReader.java
/**
 * 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());
}
 
源代码15 项目: TencentKona-8   文件: WaveFloatFileReader.java
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;
}
 
源代码16 项目: TencentKona-8   文件: WaveExtensibleFileReader.java
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;
}
 
源代码17 项目: dragonwell8_jdk   文件: AiffFileReader.java
/**
 * 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 {
    AudioFileFormat fileFormat = null;
    InputStream urlStream = url.openStream();       // throws IOException
    try {
        fileFormat = getCOMM(urlStream, false);
    } finally {
        urlStream.close();
    }
    return fileFormat;
}
 
源代码18 项目: dragonwell8_jdk   文件: AiffFileReader.java
/**
 * 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;
}
 
源代码19 项目: dragonwell8_jdk   文件: AiffFileReader.java
/**
 * 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());
}
 
源代码20 项目: TencentKona-8   文件: WaveFloatFileReader.java
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;
}
 
源代码21 项目: dragonwell8_jdk   文件: WaveFloatFileReader.java
public AudioFileFormat getAudioFileFormat(InputStream stream)
        throws UnsupportedAudioFileException, IOException {

    stream.mark(200);
    AudioFileFormat format;
    try {
        format = internal_getAudioFileFormat(stream);
    } finally {
        stream.reset();
    }
    return format;
}
 
源代码22 项目: dragonwell8_jdk   文件: WaveFloatFileReader.java
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;
}
 
源代码23 项目: dragonwell8_jdk   文件: WaveFloatFileReader.java
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;
}
 
源代码24 项目: TencentKona-8   文件: WaveExtensibleFileReader.java
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;
}
 
源代码25 项目: dragonwell8_jdk   文件: WaveExtensibleFileReader.java
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;
}
 
源代码26 项目: dragonwell8_jdk   文件: WaveExtensibleFileReader.java
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;
}
 
源代码27 项目: dragonwell8_jdk   文件: ReadersExceptions.java
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");
}
 
源代码28 项目: TencentKona-8   文件: JavaSoundAudioClip.java
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");
    }
}
 
源代码29 项目: TencentKona-8   文件: JavaSoundAudioClip.java
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;
}
 
源代码30 项目: TencentKona-8   文件: WaveExtensibleFileReader.java
public AudioFileFormat getAudioFileFormat(InputStream stream)
        throws UnsupportedAudioFileException, IOException {

    stream.mark(200);
    AudioFileFormat format;
    try {
        format = internal_getAudioFileFormat(stream);
    } finally {
        stream.reset();
    }
    return format;
}