Mp4TagCoverFieldpublic class Mp4TagCoverField extends Mp4TagBinaryField Represents Cover Art
Note:Within this library we have a seperate TagCoverField for every image stored, however this does not map
very directly to how they are physically stored within a file, because all are stored under a single covr atom, so
a more complex conversion has to be done then for other fields when writing multiple images back to file. |
Fields Summary |
---|
private Mp4FieldType | imageType | private int | dataAndHeaderSize |
Constructors Summary |
---|
public Mp4TagCoverField()Empty CoverArt Field
super(Mp4FieldKey.ARTWORK.getFieldName());
| public Mp4TagCoverField(ByteBuffer raw, Mp4FieldType imageType)Construct CoverField by reading data from audio file
super(Mp4FieldKey.ARTWORK.getFieldName(), raw);
this.imageType=imageType;
if(!Mp4FieldType.isCoverArtType(imageType))
{
logger.warning(ErrorMessage.MP4_IMAGE_FORMAT_IS_NOT_TO_EXPECTED_TYPE.getMsg(imageType));
}
| public Mp4TagCoverField(byte[] data)Construct new cover art with binarydata provided
Identifies the imageType by looking at the data
super(Mp4FieldKey.ARTWORK.getFieldName(), data);
//Read signature
if (ImageFormats.binaryDataIsPngFormat(data))
{
imageType = Mp4FieldType.COVERART_PNG;
}
else if (ImageFormats.binaryDataIsJpgFormat(data))
{
imageType = Mp4FieldType.COVERART_JPEG;
}
else if (ImageFormats.binaryDataIsGifFormat(data))
{
imageType = Mp4FieldType.COVERART_GIF;
}
else if (ImageFormats.binaryDataIsBmpFormat(data))
{
imageType = Mp4FieldType.COVERART_BMP;
}
else
{
logger.warning(ErrorMessage.GENERAL_UNIDENITIFED_IMAGE_FORMAT.getMsg());
imageType = Mp4FieldType.COVERART_PNG;
}
|
Methods Summary |
---|
protected void | build(java.nio.ByteBuffer raw)
Mp4BoxHeader header = new Mp4BoxHeader(raw);
dataSize = header.getDataLength();
dataAndHeaderSize = header.getLength();
//Skip the version and length fields
raw.position(raw.position() + Mp4DataBox.PRE_DATA_LENGTH);
//Read the raw data into byte array
this.dataBytes = new byte[dataSize - Mp4DataBox.PRE_DATA_LENGTH];
raw.get(dataBytes,0,dataBytes.length);
//Is there room for another atom (remember actually passed all the data so unless Covr is last atom
//there will be room even though more likely to be for the text top level atom)
int positionAfterDataAtom = raw.position();
if (raw.position() + Mp4BoxHeader.HEADER_LENGTH <= raw.limit())
{
//Is there a following name field (not the norm)
Mp4BoxHeader nameHeader = new Mp4BoxHeader(raw);
if (nameHeader.getId().equals(Mp4NameBox.IDENTIFIER))
{
dataSize += nameHeader.getDataLength();
dataAndHeaderSize += nameHeader.getLength();
}
else
{
raw.position(positionAfterDataAtom);
}
}
//After returning buffers position will be after the end of this atom
| public int | getDataAndHeaderSize()
return dataAndHeaderSize;
| public Mp4FieldType | getFieldType()Return field type, for artwork this also identifies the imagetype
return imageType;
| public static java.lang.String | getMimeTypeForImageType(Mp4FieldType imageType)
if(imageType==Mp4FieldType.COVERART_PNG)
{
return ImageFormats.MIME_TYPE_PNG;
}
else if(imageType==Mp4FieldType.COVERART_JPEG)
{
return ImageFormats.MIME_TYPE_JPEG;
}
else if(imageType==Mp4FieldType.COVERART_GIF)
{
return ImageFormats.MIME_TYPE_GIF;
}
else if(imageType==Mp4FieldType.COVERART_BMP)
{
return ImageFormats.MIME_TYPE_BMP;
}
else
{
return null;
}
| public boolean | isBinary()
return true;
| public java.lang.String | toString()
return imageType +":" + dataBytes.length + "bytes";
|
|