public class MP3AudioInputStream
extends javax.sound.sampled.AudioInputStream
AudioInputStream
adapter for MP3ElementaryInputStream
.
Unlike a regular audio input stream, an MP3 audio input stream can have a variable frame size and can change its encoding method in mid-stream. Therefore method getFormat can return different values for each frame, and mark/reset is not supported, and method getFrameLength can not return the total number of frames in the stream.
Constructor and Description |
---|
MP3AudioInputStream(java.io.File file)
Creates an MP3AudioInputStream and reads the stream until the first
frame is reached.
|
MP3AudioInputStream(java.io.InputStream in)
Creates an MP3AudioInputStream and reads the stream until the first
frame is reached.
|
Modifier and Type | Method and Description |
---|---|
int |
available() |
void |
close() |
javax.sound.sampled.AudioFormat |
getFormat()
Returns the format of the next frame.
|
long |
getFrameLength()
Returns -1 because we don't know how many frames the stream has.
|
void |
mark(int readlimit) |
boolean |
markSupported() |
int |
read()
Throws an IOException, because the frame size is greater than 1.
|
int |
read(byte[] b,
int off,
int len)
Reads some number of bytes from the audio input stream and stores them
into the buffer array b.
|
void |
reset() |
long |
skip(long n) |
public MP3AudioInputStream(java.io.File file) throws java.io.IOException
file
- A File.java.io.IOException
- if the file does not contain an MP3 elementary stream.public MP3AudioInputStream(java.io.InputStream in) throws java.io.IOException
in
- An InputStream.java.io.IOException
- if the stream does not contain an MP3 elementary stream.public int available() throws java.io.IOException
available
in class javax.sound.sampled.AudioInputStream
java.io.IOException
public javax.sound.sampled.AudioFormat getFormat()
getFormat
in class javax.sound.sampled.AudioInputStream
public long getFrameLength()
getFrameLength
in class javax.sound.sampled.AudioInputStream
public void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in class javax.sound.sampled.AudioInputStream
java.io.IOException
public int read() throws java.io.IOException
read
in class javax.sound.sampled.AudioInputStream
java.io.IOException
public int read(byte[] b, int off, int len) throws java.io.IOException
b.length - (b.length % frameSize)
bytes will be read.read
in class javax.sound.sampled.AudioInputStream
java.io.IOException
public long skip(long n) throws java.io.IOException
skip
in class javax.sound.sampled.AudioInputStream
java.io.IOException
public void mark(int readlimit)
mark
in class javax.sound.sampled.AudioInputStream
public boolean markSupported()
markSupported
in class javax.sound.sampled.AudioInputStream
public void reset() throws java.io.IOException
reset
in class javax.sound.sampled.AudioInputStream
java.io.IOException