net.sf.ext.helliker.id3
Class MPEGAudioFrameHeader

java.lang.Object
  extended bynet.sf.ext.helliker.id3.MPEGAudioFrameHeader

public class MPEGAudioFrameHeader
extends java.lang.Object

This class reads through the file specified and tries to find an mpeg frame. It then reads data from the header of the first frame encountered.

Version History
1.8 - 2002.10/20 by Tech
Fixed some bugs when detecting the first MPEG frame
1.7.1 - 2002.10/17 by gruni
Made Sourcecode compliant to the Sun CodingConventions
1.7 - 2002/02/25 by helliker
-Implemented a much better mpeg identification algorithm.
-Added method for computing number of frames.
1.6 - 2002/02/03 by helliker
-New algorithm for determining presence of 1st frame.
-More checks to ensure stability.
1.5 - 2002/01/22 by helliker
-Made stupid mistake that causes an infininte recursive loop when reading non-VBR files.
1.4 - 2002/01/21 by helliker
-Added support for VBR files.
-Added fields for padding and private bits.
-Added getFrameLength method.
1.3 - 2001/11/10 by helliker
-Fixed file handle leaks.
-Added accessor to find the offset of the MPEG data.
1.2 - 2001/10/19 by helliker
All set for release.

Version:
1.8
Author:
Jonathan Hilliker

Field Summary
static int MONO_MODE
          Mono
static int MPEG_L_1
          Layer I
static int MPEG_L_2
          Layer II
static int MPEG_L_3
          Layer III
static int MPEG_V_1
          MPEG Version 1
static int MPEG_V_2
          MPEG Version 2
static int MPEG_V_25
          MPEG Version 2.5
 
Constructor Summary
MPEGAudioFrameHeader(java.io.File mp3)
          Create an MPEGAudioFrameHeader from the file specified.
MPEGAudioFrameHeader(java.io.File mp3, int offset)
          Create an MPEGAudioFrameHeader from the file specified.
 
Method Summary
 int getBitRate()
          Returns the bitrate of this mpeg.
 java.lang.String getChannelMode()
          Return the channel mode of the mpeg in string form.
 java.lang.String getEmphasis()
          Returns the emphasis.
 int getFrameLength()
          Computes the length of the frame found.
 java.lang.String getLayer()
          Return the layer description of the mpeg in string form.
 long getLocation()
          Returns the offset at which the first mpeg frame was found in the file.
 int getNumFrames()
          Returns the number of frames in this mpeg file.
 int getSampleRate()
          Returns the sample rate of the mpeg in Hz
 int getVBRPlayingTime()
          If this is a VBR file, return an accurate playing time of this mpeg.
 java.lang.String getVersion()
          Return the version of the mpeg in string form.
 boolean hasPadding()
          Returns true if the mpeg frames are padded in this file.
 boolean isCopyrighted()
          Returns true if the audio is copyrighted
 boolean isMP3()
          Returns true if the file passed to the constructor is an mp3 (MPEG layer III).
 boolean isOriginal()
          Returns true if this is the original media
 boolean isProtected()
          Returns true if this mpeg is protected by CRC
 boolean isVBR()
          Returns true if this mpeg is encoded in VBR
 boolean privateBitSet()
          Returns true if the private bit is set.
 java.lang.String toString()
          Return a string representation of this object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MPEG_V_25

public static final int MPEG_V_25
MPEG Version 2.5

See Also:
Constant Field Values

MPEG_V_2

public static final int MPEG_V_2
MPEG Version 2

See Also:
Constant Field Values

MPEG_V_1

public static final int MPEG_V_1
MPEG Version 1

See Also:
Constant Field Values

MPEG_L_3

public static final int MPEG_L_3
Layer III

See Also:
Constant Field Values

MPEG_L_2

public static final int MPEG_L_2
Layer II

See Also:
Constant Field Values

MPEG_L_1

public static final int MPEG_L_1
Layer I

See Also:
Constant Field Values

MONO_MODE

public static final int MONO_MODE
Mono

See Also:
Constant Field Values
Constructor Detail

MPEGAudioFrameHeader

public MPEGAudioFrameHeader(java.io.File mp3)
                     throws NoMPEGFramesException,
                            java.io.FileNotFoundException,
                            java.io.IOException,
                            CorruptHeaderException
Create an MPEGAudioFrameHeader from the file specified. Upon creation information will be read in from the first frame header the object encounters in the file.

Parameters:
mp3 - the file to read from
Throws:
NoMPEGFramesException - if the file is not a valid mpeg
java.io.FileNotFoundException - if an error occurs
java.io.IOException - if an error occurs
CorruptHeaderException - if an error occurs

MPEGAudioFrameHeader

public MPEGAudioFrameHeader(java.io.File mp3,
                            int offset)
                     throws NoMPEGFramesException,
                            java.io.FileNotFoundException,
                            java.io.IOException,
                            CorruptHeaderException
Create an MPEGAudioFrameHeader from the file specified. Upon creation information will be read in from the first frame header the object encounters in the file. The offset tells the object where to start searching for an MPEG frame. If you know the size of an id3v2 tag attached to the file and pass it to this ctor, it will take less time to find the frame.

Parameters:
mp3 - the file to read from
offset - the offset to start searching from
Throws:
NoMPEGFramesException - if the file is not a valid mpeg
java.io.FileNotFoundException - if an error occurs
java.io.IOException - if an error occurs
CorruptHeaderException - if an error occurs
Method Detail

getFrameLength

public int getFrameLength()
Computes the length of the frame found. This is not necessarily constant for all frames.

Returns:
the length of the frame found

toString

public java.lang.String toString()
Return a string representation of this object. Includes all information read in.

Returns:
a string representation of this object

getVersion

public java.lang.String getVersion()
Return the version of the mpeg in string form. Ex: MPEG Version 1.0

Returns:
the version of the mpeg

getLayer

public java.lang.String getLayer()
Return the layer description of the mpeg in string form. Ex: Layer III

Returns:
the layer description of the mpeg

getChannelMode

public java.lang.String getChannelMode()
Return the channel mode of the mpeg in string form. Ex: Joint Stereo (STEREO)

Returns:
the channel mode of the mpeg

getSampleRate

public int getSampleRate()
Returns the sample rate of the mpeg in Hz

Returns:
the sample rate of the mpeg in Hz

isCopyrighted

public boolean isCopyrighted()
Returns true if the audio is copyrighted

Returns:
true if the audio is copyrighted

isProtected

public boolean isProtected()
Returns true if this mpeg is protected by CRC

Returns:
true if this mpeg is protected by CRC

isOriginal

public boolean isOriginal()
Returns true if this is the original media

Returns:
true if this is the original media

isVBR

public boolean isVBR()
Returns true if this mpeg is encoded in VBR

Returns:
if VBR is present

getEmphasis

public java.lang.String getEmphasis()
Returns the emphasis. I don't know what this means, it just does it...

Returns:
the emphasis

getLocation

public long getLocation()
Returns the offset at which the first mpeg frame was found in the file.

Returns:
the offset of the mpeg data

isMP3

public boolean isMP3()
Returns true if the file passed to the constructor is an mp3 (MPEG layer III).

Returns:
true if the file is an mp3

hasPadding

public boolean hasPadding()
Returns true if the mpeg frames are padded in this file.

Returns:
true if the mpeg frames are padded in this file

privateBitSet

public boolean privateBitSet()
Returns true if the private bit is set.

Returns:
true if the private bit is set

getVBRPlayingTime

public int getVBRPlayingTime()
If this is a VBR file, return an accurate playing time of this mpeg. If this is not a VBR file -1 is returned.

Returns:
an accurate playing time of this mpeg

getBitRate

public int getBitRate()
Returns the bitrate of this mpeg. If it is a VBR file the average bitrate is returned.

Returns:
the bitrate of this mpeg (in kbps)

getNumFrames

public int getNumFrames()
Returns the number of frames in this mpeg file. This does not subtract the size of and id3v1 tag if present so it is not deadly accurate.

Returns:
the number of frames in this mpeg file