public class ID3v24TagHeader
extends java.lang.Object
This class provides methods for reading and writing the ID3V2.4 tag header.
The ID3v2.4 tag header is 10 bytes long and is the first information in the ID3v2.4 tag
.
The structure of an .mp3 file containing an ID3v2.4 tag is shown below.
An Id3v2.4 tag header has the following fields:
Field | Description | |
---|---|---|
1. | version | indicates which version of the ID3v2.x tag specification is stored in the .mp3 file. This value is always
ID3V2_4 |
2. | tagSize | holds the total size of the ID3v2.4 tag, not including the header and, if present, the footer. Simply put, since the tag header is 10 bytes long, the tagSize = total tag size - 10. If the footer is present, then the tagSize = total tag size - 20. |
3. | unsynchronization | flag used for correcting false synchronization bytes that occur in the ID3v2.4 tag header.
To understand why unsyncronization is used, it's helpful to understand a little about the format of .mp3 files as well as how an .mp3
file is played by a media player. MP3 audio data is stored in an .mp3 file as a series of frames (not to be confused with the frames
that are found in the ID3v2.4 tag in the .mp3 file). Each .mp3 audio frame contains a small bit of digital music encoded in the MP3
format as well as some meta data about the frame itself. At the beginning of each MP3 audio frame are 11 bits (sometimes 12) all set
to 1. This is called the synch signal, and it's the pattern a media player looks for when attempting to play an .mp3 file or stream.
If the player finds this 11/12 bit sequence, then it knows it has found an MP3 audio frame which can be decoded and played back.
Thus, if an MP3 player finds a synch signal (11/12 bit sequence of all 1's) within the ID3v2.4 tag, it will think it has found the synch signal and try to play the ID3v2.4 tag back as music, which it isn't. Thus, the ID3v2.4 tag may need to be unsynchonized so that MP3 players properly skip over the tag and only try to play proper MP3 audio frames. See sec 6.1 - unsynchronisation scheme of the ID3v2.4 spec |
4. | extendedHeaderPresent | flag indicating whether an extended header is present. If so, then the extended header will contain
more version specific data. |
5. | experimentalIndicator | flag indicating that the ID3v2.4 tag is in an experimental stage. |
6. | footerPresent | flag indicating whether a footer is present. If so, then the footer follows the frames, and no padding is
present. |
Modifier and Type | Field and Description |
---|---|
static int |
TAG_HEADER_SIZE
size (in bytes) of the standard ID3v2.4 tag header
|
Constructor and Description |
---|
ID3v24TagHeader()
The default constructor is called when creating a new ID3v2.4 tag header.
|
ID3v24TagHeader(java.io.InputStream inputStream)
This constructor is called when reading in an existing ID3v2.4 tag header from an .mp3 file.
|
Modifier and Type | Method and Description |
---|---|
int |
getSize()
gets the total number of bytes in the ID3v2.4 tag header.
|
int |
getTagSize()
gets the size of the ID3v2.4 tag excluding the tag header and, if present, the tag footer.
|
ID3TagVersion |
getVersion()
gets the version of the tag, which is always
ID3V2_4 . |
boolean |
isDirty()
indicates whether or not the tag header's fields have been modified.
|
boolean |
isExperimentalIndicator()
Indicates whether the ID3v2.4 tag is in an experimental stage.
|
boolean |
isExtendedHeaderPresent()
indicates whether the optional
extended header is present. |
boolean |
isFooterPresent()
Indicates whether the ID3v2.4 tag has a footer which follows the padding.
|
boolean |
isUnsynchronization()
gets whether unsynchronization was used to correct false synchronization bytes in the ID3v2.4 tag.
|
void |
save(java.io.OutputStream outputStream)
save the ID3v2.4 tag header to the .mp3 file.
|
void |
save(java.io.RandomAccessFile file)
save the ID3v2.4 tag header to the .mp3 file.
|
void |
setBuffer()
if the ID3v2.4 tag header's values have been modified, then resize the raw binary buffer and store the new values there.
|
void |
setExperimentalIndicator(boolean experimentalIndicator)
sets whether the ID3v2.4 tag is in an experimental stage.
|
void |
setExtendedHeaderPresent(boolean extendedHeaderPresent)
sets whether the optional
extended header is present. |
void |
setFooterPresent(boolean footerPresent)
sets whether the ID3v2.4 tag footer is present.
|
void |
setTagSize(int tagSize)
sets the size of the ID3v2.4 tag excluding the tag header, and if present, the tag footer.
|
void |
setUnsynchronization(boolean unsynchronization)
sets whether unsynchronization is used.
|
java.lang.String |
toString()
gets a string representation of the ID3v2.4 tag header showing the values of the standard ID3v2.4 tag header's fields.
|
public static final int TAG_HEADER_SIZE
public ID3v24TagHeader()
public ID3v24TagHeader(java.io.InputStream inputStream) throws java.io.IOException
inputStream
- input stream pointing to the end of the standard ID3v2.4 tag header in the .mp3 file.java.io.IOException
- if the tag header can not be loaded from the .mp3 file.public boolean isDirty()
setBuffer()
public ID3TagVersion getVersion()
ID3V2_4
.ID3V2_4
.public int getTagSize()
setTagSize(int)
public void setTagSize(int tagSize)
tagSize
- the size of the ID3v2.4 tag excluding the tag header and, if present, the tag footer.getTagSize()
public int getSize()
public boolean isUnsynchronization()
setUnsynchronization(boolean)
,
section 6.1 - unsynchronization scheme in the ID3v2.4 specificationpublic void setUnsynchronization(boolean unsynchronization)
unsynchronization
- boolean indicating whether unsynchronization is used.isUnsynchronization()
,
section 6.1 - unsynchronization scheme in the ID3v2.4 specificationpublic boolean isExperimentalIndicator()
setExperimentalIndicator(boolean)
public void setExperimentalIndicator(boolean experimentalIndicator)
experimentalIndicator
- boolean indicating whether the ID3v2.4 tag is in an experimental stage.isExperimentalIndicator()
public boolean isExtendedHeaderPresent()
extended header
is present. If it is, then you may acess it via the ID3v24Tag.getExtendedHeader()
method.extended header
is present.setExtendedHeaderPresent(boolean)
public void setExtendedHeaderPresent(boolean extendedHeaderPresent)
extended header
is present.extendedHeaderPresent
- boolean indicating whether the optional extended header
is present.isExtendedHeaderPresent()
public boolean isFooterPresent()
setFooterPresent(boolean)
public void setFooterPresent(boolean footerPresent)
footerPresent
- boolean indicating whether the footer is present.isFooterPresent()
public void setBuffer()
public void save(java.io.OutputStream outputStream) throws java.io.IOException
outputStream
- output stream pointing to the starting location of the ID3v2.4 tag header within the .mp3 file.java.io.IOException
- if there was an error writing the ID3v2.4 tag header to the .mp3 file.public void save(java.io.RandomAccessFile file) throws java.io.IOException
file
- random access file pointing to the starting location of the ID3v2.4 tag header within the .mp3 file.java.io.IOException
- if there was an error writing the ID3v2.4 tag header to the .mp3 file.public java.lang.String toString()
toString
in class java.lang.Object