FileDocCategorySizeDatePackage
Mp4TagCoverField.javaAPI DocJaudiotagger 2.0.46452Wed Mar 30 16:12:10 BST 2011org.jaudiotagger.tag.mp4.field

Mp4TagCoverField

public 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

param
raw
param
imageType
throws
UnsupportedEncodingException

        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

param
data
throws
UnsupportedEncodingException

        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 voidbuild(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 intgetDataAndHeaderSize()

return
data and header size

        return dataAndHeaderSize;
    
public Mp4FieldTypegetFieldType()
Return field type, for artwork this also identifies the imagetype

return
field type

        return imageType;
    
public static java.lang.StringgetMimeTypeForImageType(Mp4FieldType imageType)

param
imageType
return
the corresponding mimetype

        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 booleanisBinary()

        return true;
    
public java.lang.StringtoString()

        return imageType +":" + dataBytes.length + "bytes";