Search in sources :

Example 16 with AudioFileFormat

use of javax.sound.sampled.AudioFileFormat in project Minim by ddf.

the class JSMinim method getID3Tags.

@SuppressWarnings("unchecked")
private Map<String, Object> getID3Tags(String filename) {
    debug("Getting the properties.");
    Map<String, Object> props = new HashMap<String, Object>();
    try {
        MpegAudioFileReader reader = new MpegAudioFileReader(this);
        InputStream stream = (InputStream) createInput.invoke(fileLoader, filename);
        if (stream != null) {
            AudioFileFormat baseFileFormat = reader.getAudioFileFormat(stream, stream.available());
            stream.close();
            if (baseFileFormat instanceof TAudioFileFormat) {
                TAudioFileFormat fileFormat = (TAudioFileFormat) baseFileFormat;
                props = (Map<String, Object>) fileFormat.properties();
                if (props.size() == 0) {
                    error("No file properties available for " + filename + ".");
                } else {
                    debug("File properties: " + props.toString());
                }
            }
        }
    } catch (UnsupportedAudioFileException e) {
        error("Couldn't get the file format for " + filename + ": " + e.getMessage());
    } catch (IOException e) {
        error("Couldn't access " + filename + ": " + e.getMessage());
    } catch (Exception e) {
        error("Error invoking createInput on the file loader object: " + e.getMessage());
    }
    return props;
}
Also used : TAudioFileFormat(org.tritonus.share.sampled.file.TAudioFileFormat) UnsupportedAudioFileException(javax.sound.sampled.UnsupportedAudioFileException) HashMap(java.util.HashMap) BufferedInputStream(java.io.BufferedInputStream) AudioInputStream(javax.sound.sampled.AudioInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) AudioFileFormat(javax.sound.sampled.AudioFileFormat) TAudioFileFormat(org.tritonus.share.sampled.file.TAudioFileFormat) LineUnavailableException(javax.sound.sampled.LineUnavailableException) MalformedURLException(java.net.MalformedURLException) UnsupportedAudioFileException(javax.sound.sampled.UnsupportedAudioFileException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 17 with AudioFileFormat

use of javax.sound.sampled.AudioFileFormat in project jdk8u_jdk by JetBrains.

the class AuFileReader method getAudioFileFormat.

/**
     * 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 {
    FileInputStream fis = null;
    BufferedInputStream bis = null;
    AudioFileFormat fileFormat = null;
    AudioFormat format = null;
    // throws IOException
    fis = new FileInputStream(file);
    // part of fix for 4325421
    try {
        bis = new BufferedInputStream(fis, bisBufferSize);
        // throws UnsupportedAudioFileException
        fileFormat = getAudioFileFormat(bis);
    } finally {
        fis.close();
    }
    return fileFormat;
}
Also used : BufferedInputStream(java.io.BufferedInputStream) AudioFormat(javax.sound.sampled.AudioFormat) FileInputStream(java.io.FileInputStream) AudioFileFormat(javax.sound.sampled.AudioFileFormat)

Example 18 with AudioFileFormat

use of javax.sound.sampled.AudioFileFormat in project jdk8u_jdk by JetBrains.

the class AuFileReader method getAudioInputStream.

/**
     * 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 = null;
    BufferedInputStream bis = null;
    AudioFileFormat fileFormat = null;
    // throws IOException
    urlStream = url.openStream();
    AudioInputStream result = null;
    try {
        bis = new BufferedInputStream(urlStream, bisBufferSize);
        result = getAudioInputStream((InputStream) bis);
    } finally {
        if (result == null) {
            urlStream.close();
        }
    }
    return result;
}
Also used : AudioInputStream(javax.sound.sampled.AudioInputStream) BufferedInputStream(java.io.BufferedInputStream) DataInputStream(java.io.DataInputStream) BufferedInputStream(java.io.BufferedInputStream) AudioInputStream(javax.sound.sampled.AudioInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) AudioFileFormat(javax.sound.sampled.AudioFileFormat)

Example 19 with AudioFileFormat

use of javax.sound.sampled.AudioFileFormat in project jdk8u_jdk by JetBrains.

the class AiffFileReader method getAudioFileFormat.

// METHODS TO IMPLEMENT AudioFileReader
/**
     * Obtains the audio file format of the input stream provided.  The stream must
     * point to valid audio file data.  In general, audio file providers may
     * need to read some data from the stream before determining whether they
     * support it.  These parsers must
     * be able to mark the stream, read enough data to determine whether they
     * support the stream, and, if not, reset the stream's read pointer to its original
     * position.  If the input stream does not support this, this method may fail
     * with an IOException.
     * @param stream the input stream from which file format information should be
     * extracted
     * @return an <code>AudioFileFormat</code> object describing the audio file format
     * @throws UnsupportedAudioFileException if the stream does not point to valid audio
     * file data recognized by the system
     * @throws IOException if an I/O exception occurs
     * @see InputStream#markSupported
     * @see InputStream#mark
     */
public AudioFileFormat getAudioFileFormat(InputStream stream) throws UnsupportedAudioFileException, IOException {
    // fix for 4489272: AudioSystem.getAudioFileFormat() fails for InputStream, but works for URL
    AudioFileFormat aff = getCOMM(stream, true);
    // the following is not strictly necessary - but was implemented like that in 1.3.0 - 1.4.1
    // so I leave it as it was. May remove this for 1.5.0
    stream.reset();
    return aff;
}
Also used : AudioFileFormat(javax.sound.sampled.AudioFileFormat)

Example 20 with AudioFileFormat

use of javax.sound.sampled.AudioFileFormat in project jdk8u_jdk by JetBrains.

the class AuFileReader method getAudioInputStream.

/**
     * 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 = null;
    BufferedInputStream bis = null;
    AudioFileFormat fileFormat = null;
    // throws IOException
    fis = new FileInputStream(file);
    AudioInputStream result = null;
    // part of fix for 4325421
    try {
        bis = new BufferedInputStream(fis, bisBufferSize);
        result = getAudioInputStream((InputStream) bis);
    } finally {
        if (result == null) {
            fis.close();
        }
    }
    return result;
}
Also used : AudioInputStream(javax.sound.sampled.AudioInputStream) BufferedInputStream(java.io.BufferedInputStream) DataInputStream(java.io.DataInputStream) BufferedInputStream(java.io.BufferedInputStream) AudioInputStream(javax.sound.sampled.AudioInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileInputStream(java.io.FileInputStream) AudioFileFormat(javax.sound.sampled.AudioFileFormat)

Aggregations

AudioFileFormat (javax.sound.sampled.AudioFileFormat)32 AudioInputStream (javax.sound.sampled.AudioInputStream)20 FileInputStream (java.io.FileInputStream)18 InputStream (java.io.InputStream)13 BufferedInputStream (java.io.BufferedInputStream)11 AudioFormat (javax.sound.sampled.AudioFormat)10 DataInputStream (java.io.DataInputStream)9 UnsupportedAudioFileException (javax.sound.sampled.UnsupportedAudioFileException)8 File (java.io.File)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 PushbackInputStream (java.io.PushbackInputStream)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 URLConnection (java.net.URLConnection)1 Type (javax.sound.sampled.AudioFileFormat.Type)1 LineUnavailableException (javax.sound.sampled.LineUnavailableException)1 Mixer (javax.sound.sampled.Mixer)1