Better handling of misnamed MP3/OGG files. (part of #120)
This also catches more MP3 loading errors that could occur and properly cleans up resources. Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
This commit is contained in:
@@ -76,8 +76,9 @@ public class Mp3InputStream extends InputStream implements AudioInputStream {
|
||||
/**
|
||||
* Create a new stream to decode MP3 data.
|
||||
* @param input the input stream from which to read the MP3 file
|
||||
* @throws IOException failure to read the header from the input stream
|
||||
*/
|
||||
public Mp3InputStream(InputStream input) {
|
||||
public Mp3InputStream(InputStream input) throws IOException {
|
||||
decoder = new Decoder();
|
||||
bitstream = new Bitstream(input);
|
||||
try {
|
||||
@@ -85,6 +86,10 @@ public class Mp3InputStream extends InputStream implements AudioInputStream {
|
||||
} catch (BitstreamException e) {
|
||||
Log.error(e);
|
||||
}
|
||||
if (header == null) {
|
||||
close();
|
||||
throw new IOException("Failed to read header from MP3 input stream.");
|
||||
}
|
||||
|
||||
channels = (header.mode() == Header.SINGLE_CHANNEL) ? 1 : 2;
|
||||
sampleRate = header.frequency();
|
||||
|
||||
Reference in New Issue
Block a user