Class Mp3FrameReader


  • public class Mp3FrameReader
    extends java.lang.Object
    Handles reading MP3 frames from a stream.
    • Constructor Detail

      • Mp3FrameReader

        public Mp3FrameReader​(SeekableInputStream inputStream,
                              byte[] frameBuffer)
        Parameters:
        inputStream - Input buffer to read from
        frameBuffer - Array to store the frame data in
    • Method Detail

      • scanForFrame

        public boolean scanForFrame​(int bytesToCheck,
                                    boolean throwOnLimit)
                             throws java.io.IOException
        Parameters:
        bytesToCheck - The maximum number of bytes to check before throwing an IllegalStateException
        throwOnLimit - Whether to throw an exception when maximum number of bytes is reached, but no frame has been found and EOF has not been reached.
        Returns:
        True if a frame was found, false if EOF was encountered.
        Throws:
        java.io.IOException - On IO error
        java.lang.IllegalStateException - If the maximum number of bytes to check was reached before a frame was found
      • fillFrameBuffer

        public boolean fillFrameBuffer()
                                throws java.io.IOException
        Fills the buffer for the current frame. If no frame header has been read previously, it will first scan for the sync bytes of the next frame in the stream.
        Returns:
        False if EOF was encountered while looking for the next frame, true otherwise
        Throws:
        java.io.IOException - On IO error
      • nextFrame

        public void nextFrame()
        Forget the current frame and make next calls look for the next frame.
      • getFrameStartPosition

        public long getFrameStartPosition()
        Returns:
        The start position of the current frame in the stream.
      • getFrameSize

        public int getFrameSize()
        Returns:
        Size of the current frame in bytes.
      • appendToScanBuffer

        public void appendToScanBuffer​(byte[] data,
                                       int offset,
                                       int length)
        Append some bytes to the frame sync scan buffer. This must be called when some bytes have been read externally that may actually be part of the next frame header.
        Parameters:
        data - The buffer to copy from
        offset - The offset in the buffer
        length - The length of the region to copy