Mp3dings 
20100427

helliker.id3
Class MPEGAudioFrameHeader

java.lang.Object
  extended by helliker.id3.MPEGAudioFrameHeader

public class MPEGAudioFrameHeader
extends 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:
1.8
Author:
Jonathan Hilliker

Field Summary
static int FREE_FORMAT
           
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
static int NULL
           
 
Constructor Summary
MPEGAudioFrameHeader(File mp3)
          Create an MPEGAudioFrameHeader from the file specified.
MPEGAudioFrameHeader(File mp3, int minSyncRange)
          Create an MPEGAudioFrameHeader from the file specified.
 
Method Summary
 boolean analyzeVBR()
          Analyzes a VBR file that does not have a XING of VBRI header.
 int calculateBitrate(long length)
          Calculates the bibtrate from the length of an unpadded frame.
 int getBitRate()
          Returns the bitrate of this mpeg.
 String getChannelMode()
          Return the channel mode of the mpeg in string form.
 String getEmphasis()
          Returns the emphasis.
 int getFrameLength()
          Computes the length of the frame found.
 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()
          Returns the playing time of a variable bitrate file.
 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
static void main(String[] argv)
           
 boolean privateBitSet()
          Returns true if the private bit is set.
 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

FREE_FORMAT

public static final int FREE_FORMAT
See Also:
Constant Field Values

NULL

public static final int NULL
See Also:
Constant Field Values

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(File mp3)
                     throws NoMPEGFramesException,
                            IOException
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
FileNotFoundException - if an error occurs
IOException - if an error occurs

MPEGAudioFrameHeader

public MPEGAudioFrameHeader(File mp3,
                            int minSyncRange)
                     throws NoMPEGFramesException,
                            IOException
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
minSyncRange - this is the minimum length of the file that is searched for consecutive headers
Throws:
NoMPEGFramesException - if the file is not a valid mpeg
FileNotFoundException - if an error occurs
IOException - 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

calculateBitrate

public int calculateBitrate(long length)
Calculates the bibtrate from the length of an unpadded frame. This is the inverse of the calculation performed by getFrameLength().

Parameters:
length - the length in bytes of an unpadded frame

toString

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

Overrides:
toString in class Object
Returns:
a string representation of this object

getVersion

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

Returns:
the version of the mpeg

getLayer

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

Returns:
the layer description of the mpeg

getChannelMode

public 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 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()
Returns the playing time of a variable bitrate file. For VBR files with XING or VBRI header, this method returns the playing time read from the header. For VBR files without header this method will return NULL or the actual playing time if a previous call to analyzeVBR() succeeded.

Returns:
the playing time of this mpeg in seconds or NULL

analyzeVBR

public boolean analyzeVBR()
                   throws IOException
Analyzes a VBR file that does not have a XING of VBRI header.

Returns:
true iff the mp3 file is a VBR file without header, had not previously been analyzed successfully, and was successfully analyzed as a result of calling this method.
Throws:
IOException

getBitRate

public int getBitRate()
Returns the bitrate of this mpeg. For VBR files with XING or VBRI header, this method returns the average bit rate read from the header. For VBR files without header this method will return NULL or the actual average bitrate if a previous call to analyzeVBR() succeeded.

Returns:
the bitrate of this mpeg (in kbps)

getNumFrames

public int getNumFrames()
Returns the number of frames in this mpeg file. For CBR files, this does not subtract the size of an id3v1 tag if present so it is not deadly accurate. For VBR files with XING or VBRI header, this method returns the number of frames read from the header. For VBR files without header this method will return NULL or the actual framecount if a previous call to analyzeVBR() succeeded.

Returns:
the number of frames in this mpeg file

main

public static void main(String[] argv)
                 throws Exception
Throws:
Exception

Mp3dings 
20100427