use of javax.sound.sampled.AudioFileFormat in project jdk8u_jdk by JetBrains.
the class WaveFileReader 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 {
AudioFileFormat fileFormat = null;
// throws IOException
FileInputStream fis = new FileInputStream(file);
// part of fix for 4325421
try {
fileFormat = getFMT(fis, false);
} finally {
fis.close();
}
return fileFormat;
}
use of javax.sound.sampled.AudioFileFormat in project jdk8u_jdk by JetBrains.
the class WaveFileReader method getAudioFileFormat.
/**
* 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 {
// throws IOException
InputStream urlStream = url.openStream();
AudioFileFormat fileFormat = null;
try {
fileFormat = getFMT(urlStream, false);
} finally {
urlStream.close();
}
return fileFormat;
}
use of javax.sound.sampled.AudioFileFormat in project jdk8u_jdk by JetBrains.
the class WaveFileReader method getAudioFileFormat.
/**
* 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 = getFMT(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;
}
use of javax.sound.sampled.AudioFileFormat in project jdk8u_jdk by JetBrains.
the class WaveFloatFileReader method internal_getAudioFileFormat.
private AudioFileFormat internal_getAudioFileFormat(InputStream stream) throws UnsupportedAudioFileException, IOException {
RIFFReader riffiterator = new RIFFReader(stream);
if (!riffiterator.getFormat().equals("RIFF"))
throw new UnsupportedAudioFileException();
if (!riffiterator.getType().equals("WAVE"))
throw new UnsupportedAudioFileException();
boolean fmt_found = false;
boolean data_found = false;
int channels = 1;
long samplerate = 1;
int framesize = 1;
int bits = 1;
while (riffiterator.hasNextChunk()) {
RIFFReader chunk = riffiterator.nextChunk();
if (chunk.getFormat().equals("fmt ")) {
fmt_found = true;
int format = chunk.readUnsignedShort();
if (// WAVE_FORMAT_IEEE_FLOAT only
format != 3)
throw new UnsupportedAudioFileException();
channels = chunk.readUnsignedShort();
samplerate = chunk.readUnsignedInt();
/* framerate = */
chunk.readUnsignedInt();
framesize = chunk.readUnsignedShort();
bits = chunk.readUnsignedShort();
}
if (chunk.getFormat().equals("data")) {
data_found = true;
break;
}
}
if (!fmt_found)
throw new UnsupportedAudioFileException();
if (!data_found)
throw new UnsupportedAudioFileException();
AudioFormat audioformat = new AudioFormat(Encoding.PCM_FLOAT, samplerate, bits, channels, framesize, samplerate, false);
AudioFileFormat fileformat = new AudioFileFormat(AudioFileFormat.Type.WAVE, audioformat, AudioSystem.NOT_SPECIFIED);
return fileformat;
}
use of javax.sound.sampled.AudioFileFormat in project jdk8u_jdk by JetBrains.
the class WaveFloatFileReader method getAudioFileFormat.
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;
}
Aggregations