java.lang.Object
java.io.InputStream
javax.sound.sampled.AudioInputStream
org.monte.media.mp3.MP3AudioInputStream
- All Implemented Interfaces:
Closeable,AutoCloseable
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.
- Author:
- Werner Randelshofer
-
Field Summary
Fields inherited from class javax.sound.sampled.AudioInputStream
format, frameLength, framePos, frameSize -
Constructor Summary
ConstructorsConstructorDescriptionMP3AudioInputStream(File file) Creates an MP3AudioInputStream and reads the stream until the first frame is reached.Creates an MP3AudioInputStream and reads the stream until the first frame is reached. -
Method Summary
Modifier and TypeMethodDescriptionintvoidclose()Returns the format of the next frame.longReturns -1 because we don't know how many frames the stream has.voidmark(int readlimit) booleanintread()Throws an IOException, because the frame size is greater than 1.intread(byte[] b, int off, int len) Reads some number of bytes from the audio input stream and stores them into the buffer array b.voidreset()longskip(long n) Methods inherited from class javax.sound.sampled.AudioInputStream
readMethods inherited from class java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
-
Constructor Details
-
MP3AudioInputStream
Creates an MP3AudioInputStream and reads the stream until the first frame is reached.- Parameters:
file- A File.- Throws:
IOException- if the file does not contain an MP3 elementary stream.
-
MP3AudioInputStream
Creates an MP3AudioInputStream and reads the stream until the first frame is reached.- Parameters:
in- An InputStream.- Throws:
IOException- if the stream does not contain an MP3 elementary stream.
-
-
Method Details
-
available
- Overrides:
availablein classAudioInputStream- Throws:
IOException
-
getFormat
Returns the format of the next frame. Returns null if the stream is not positioned inside a frame.- Overrides:
getFormatin classAudioInputStream
-
getFrameLength
public long getFrameLength()Returns -1 because we don't know how many frames the stream has.- Overrides:
getFrameLengthin classAudioInputStream
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classAudioInputStream- Throws:
IOException
-
read
Throws an IOException, because the frame size is greater than 1.- Overrides:
readin classAudioInputStream- Throws:
IOException
-
read
Reads some number of bytes from the audio input stream and stores them into the buffer array b. The number of bytes actually read is returned as an integer. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown. This method will always read an integral number of frames. If the length of the array is not an integral number of frames, a maximum ofb.length - (b.length % frameSize)bytes will be read.- Overrides:
readin classAudioInputStream- Returns:
- Returns the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.
- Throws:
IOException
-
skip
- Overrides:
skipin classAudioInputStream- Throws:
IOException
-
mark
public void mark(int readlimit) - Overrides:
markin classAudioInputStream
-
markSupported
public boolean markSupported()- Overrides:
markSupportedin classAudioInputStream
-
reset
- Overrides:
resetin classAudioInputStream- Throws:
IOException
-