Methods Summary |
---|
public TagField | createArtworkField(byte[] data)Create artwork field
return new Mp4TagCoverField(data);
|
public TagField | createField(org.jaudiotagger.tag.images.Artwork artwork)Create artwork field
return new Mp4TagCoverField(artwork.getBinaryData());
|
public TagField | createField(FieldKey genericKey, java.lang.String value)Create Tag Field using generic key
This should use the correct subclass for the key
if (value == null)
{
throw new IllegalArgumentException(ErrorMessage.GENERAL_INVALID_NULL_ARGUMENT.getMsg());
}
if (genericKey == null)
{
throw new KeyNotFoundException();
}
//Special handling for these number fields
if(
(genericKey== FieldKey.TRACK)||
(genericKey== FieldKey.TRACK_TOTAL)||
(genericKey== FieldKey.DISC_NO)||
(genericKey== FieldKey.DISC_TOTAL)
)
{
try
{
int number = Integer.parseInt(value);
if(genericKey== FieldKey.TRACK)
{
return new Mp4TrackField(number);
}
else if(genericKey== FieldKey.TRACK_TOTAL)
{
return new Mp4TrackField(0,number);
}
else if(genericKey== FieldKey.DISC_NO)
{
return new Mp4DiscNoField(number);
}
else if(genericKey== FieldKey.DISC_TOTAL)
{
return new Mp4DiscNoField(0,number);
}
}
catch(NumberFormatException nfe)
{
//If not number we want to convert to an expected exception (which is not a RuntimeException)
//so can be handled properly by calling program
throw new FieldDataInvalidException("Value "+value + " is not a number as required",nfe);
}
}
//Default for all other fields
return createField(tagFieldToMp4Field.get(genericKey), value);
|
public TagField | createField(Mp4FieldKey mp4FieldKey, java.lang.String value)Create Tag Field using mp4 key
Uses the correct subclass for the key
if (value == null)
{
throw new IllegalArgumentException(ErrorMessage.GENERAL_INVALID_NULL_ARGUMENT.getMsg());
}
if (mp4FieldKey == null)
{
throw new KeyNotFoundException();
}
//This is boolean stored as 1, but calling program might setField as 'true' so we handle this
//case internally
if(mp4FieldKey==Mp4FieldKey.COMPILATION)
{
if(value.equals("true"))
{
value= Mp4TagByteField.TRUE_VALUE;
}
return new Mp4TagByteField(mp4FieldKey, value, mp4FieldKey.getFieldLength());
}
else if(mp4FieldKey==Mp4FieldKey.GENRE)
{
return createGenreField(value);
}
else if(mp4FieldKey.getSubClassFieldType()==Mp4TagFieldSubType.DISC_NO)
{
return new Mp4DiscNoField(value);
}
else if(mp4FieldKey.getSubClassFieldType()==Mp4TagFieldSubType.TRACK_NO)
{
return new Mp4TrackField(value);
}
else if(mp4FieldKey.getSubClassFieldType()==Mp4TagFieldSubType.BYTE)
{
return new Mp4TagByteField(mp4FieldKey, value, mp4FieldKey.getFieldLength());
}
else if(mp4FieldKey.getSubClassFieldType()==Mp4TagFieldSubType.NUMBER)
{
return new Mp4TagTextNumberField(mp4FieldKey.getFieldName(), value);
}
else if(mp4FieldKey.getSubClassFieldType()==Mp4TagFieldSubType.REVERSE_DNS)
{
return new Mp4TagReverseDnsField(mp4FieldKey, value);
}
else if(mp4FieldKey.getSubClassFieldType()==Mp4TagFieldSubType.ARTWORK)
{
throw new UnsupportedOperationException(ErrorMessage.ARTWORK_CANNOT_BE_CREATED_WITH_THIS_METHOD.getMsg());
}
else if(mp4FieldKey.getSubClassFieldType()==Mp4TagFieldSubType.TEXT)
{
return new Mp4TagTextField(mp4FieldKey.getFieldName(), value);
}
else if(mp4FieldKey.getSubClassFieldType()==Mp4TagFieldSubType.UNKNOWN)
{
throw new UnsupportedOperationException(ErrorMessage.DO_NOT_KNOW_HOW_TO_CREATE_THIS_ATOM_TYPE.getMsg(mp4FieldKey.getFieldName()));
}
else
{
throw new UnsupportedOperationException(ErrorMessage.DO_NOT_KNOW_HOW_TO_CREATE_THIS_ATOM_TYPE.getMsg(mp4FieldKey.getFieldName()));
}
|
private TagField | createGenreField(java.lang.String content)Create genre field
If the content can be parsed to one of the known values use the genre field otherwise
use the custom field.
if (content == null)
{
throw new IllegalArgumentException(ErrorMessage.GENERAL_INVALID_NULL_ARGUMENT.getMsg());
}
//Always write as text
if(TagOptionSingleton.getInstance().isWriteMp4GenresAsText())
{
return new Mp4TagTextField(GENRE_CUSTOM.getFieldName(), content);
}
if (Mp4GenreField.isValidGenre(content))
{
return new Mp4GenreField(content);
}
else
{
return new Mp4TagTextField(GENRE_CUSTOM.getFieldName(), content);
}
|
public void | deleteField(FieldKey genericKey)Delete fields with this generic key
if (genericKey == null)
{
throw new KeyNotFoundException();
}
super.deleteField(tagFieldToMp4Field.get(genericKey).getFieldName());
|
public void | deleteField(Mp4FieldKey mp4Key)Delete fields with this mp4key
if (mp4Key == null)
{
throw new KeyNotFoundException();
}
super.deleteField(mp4Key.getFieldName());
|
public java.util.List | get(Mp4FieldKey mp4FieldKey)Retrieve the values that exists for this mp4keyId (this is the internalid actually used)
if (mp4FieldKey == null)
{
throw new KeyNotFoundException();
}
return super.getFields(mp4FieldKey.getFieldName());
|
public java.util.List | getArtworkList()
List<TagField> coverartList = get(Mp4FieldKey.ARTWORK);
List<Artwork> artworkList = new ArrayList<Artwork>(coverartList.size());
for(TagField next:coverartList)
{
Mp4TagCoverField mp4CoverArt = (Mp4TagCoverField)next;
Artwork artwork = ArtworkFactory.getNew();
artwork.setBinaryData(mp4CoverArt.getData());
artwork.setMimeType(Mp4TagCoverField.getMimeTypeForImageType(mp4CoverArt.getFieldType()));
artworkList.add(artwork);
}
return artworkList;
|
public java.util.List | getFields(FieldKey genericKey)Maps the generic key to the mp4 key and return the list of values for this field
if (genericKey == null)
{
throw new KeyNotFoundException();
}
return super.getFields(tagFieldToMp4Field.get(genericKey).getFieldName());
|
public java.lang.String | getFirst(Mp4FieldKey mp4Key)Retrieve the first value that exists for this mp4key
if (mp4Key == null)
{
throw new KeyNotFoundException();
}
return super.getFirst(mp4Key.getFieldName());
|
public Mp4TagField | getFirstField(FieldKey genericKey)
if (genericKey == null)
{
throw new KeyNotFoundException();
}
return (Mp4TagField)super.getFirstField(tagFieldToMp4Field.get(genericKey).getFieldName());
|
public Mp4TagField | getFirstField(Mp4FieldKey mp4Key)
if (mp4Key == null)
{
throw new KeyNotFoundException();
}
return (Mp4TagField) super.getFirstField(mp4Key.getFieldName());
|
public java.lang.String | getValue(FieldKey genericKey, int index)Retrieve the indexed value that exists for this generic key
if (genericKey == null)
{
throw new KeyNotFoundException();
}
if(genericKey== FieldKey.GENRE)
{
List<TagField> genres = getFields(GENRE.getFieldName());
if (genres.size() == 0)
{
genres = getFields(GENRE_CUSTOM.getFieldName());
}
if(genres.size()>index)
{
return ((TagTextField)genres.get(index)).getContent();
}
else
{
return "";
}
}
else if(genericKey== FieldKey.TRACK)
{
List<TagField> list = get(tagFieldToMp4Field.get(genericKey));
if(list.size()>index)
{
Mp4TrackField trackField = (Mp4TrackField)list.get(index);
if(trackField.getTrackNo()>0)
{
return String.valueOf(trackField.getTrackNo());
}
}
}
else if(genericKey== FieldKey.TRACK_TOTAL)
{
List<TagField> list = get(tagFieldToMp4Field.get(genericKey));
if(list.size()>index)
{
Mp4TrackField trackField = (Mp4TrackField)list.get(index);
if(trackField.getTrackTotal()>0)
{
return String.valueOf(trackField.getTrackTotal());
}
}
}
else if(genericKey== FieldKey.DISC_NO)
{
List<TagField> list = get(tagFieldToMp4Field.get(genericKey));
if(list.size()>index)
{
Mp4DiscNoField discField = (Mp4DiscNoField)list.get(index);
if(discField.getDiscNo()>0)
{
return String.valueOf(discField.getDiscNo());
}
}
}
else if(genericKey== FieldKey.DISC_TOTAL)
{
List<TagField> list = get(tagFieldToMp4Field.get(genericKey));
if(list.size()>index)
{
Mp4DiscNoField discField = (Mp4DiscNoField)list.get(index);
if(discField.getDiscTotal()>0)
{
return String.valueOf(discField.getDiscTotal());
}
}
}
else
{
return super.getItem(tagFieldToMp4Field.get(genericKey).getFieldName(), index);
}
return "";
|
public boolean | hasField(FieldKey genericKey)
Mp4FieldKey mp4FieldKey = tagFieldToMp4Field.get(genericKey);
return getFields(mp4FieldKey.getFieldName()).size() != 0;
|
public boolean | hasField(Mp4FieldKey mp4FieldKey)
return getFields(mp4FieldKey.getFieldName()).size() != 0;
|
protected boolean | isAllowedEncoding(java.lang.String enc)
return enc.equals(Mp4BoxHeader.CHARSET_UTF_8);
|
public void | setField(TagField field)Set field, special handling for track and disc because they hold two fields
if (field == null)
{
return;
}
if(field.getId().equals(TRACK.getFieldName()))
{
List<TagField> list = fields.get(field.getId());
if(list==null||list.size()==0)
{
super.setField(field);
}
else
{
Mp4TrackField existingTrackField = (Mp4TrackField)list.get(0);
Mp4TrackField newTrackField = (Mp4TrackField)field;
Short trackNo = existingTrackField.getTrackNo();
Short trackTotal = existingTrackField.getTrackTotal();
if(newTrackField.getTrackNo()>0 )
{
trackNo = newTrackField.getTrackNo();
}
if(newTrackField.getTrackTotal()>0 )
{
trackTotal = newTrackField.getTrackTotal();
}
Mp4TrackField mergedTrackField = new Mp4TrackField(trackNo,trackTotal);
super.setField(mergedTrackField);
}
}
else if(field.getId().equals(DISCNUMBER.getFieldName()))
{
List<TagField> list = fields.get(field.getId());
if(list==null||list.size()==0)
{
super.setField(field);
}
else
{
Mp4DiscNoField existingDiscNoField = (Mp4DiscNoField)list.get(0);
Mp4DiscNoField newDiscNoField = (Mp4DiscNoField)field;
Short discNo = existingDiscNoField.getDiscNo();
Short discTotal = existingDiscNoField.getDiscTotal();
if(newDiscNoField.getDiscNo()>0 )
{
discNo = newDiscNoField.getDiscNo();
}
if(newDiscNoField.getDiscTotal()>0 )
{
discTotal = newDiscNoField.getDiscTotal();
}
Mp4DiscNoField mergedDiscNoField = new Mp4DiscNoField(discNo,discTotal);
super.setField(mergedDiscNoField);
}
}
else
{
super.setField(field);
}
|
public java.lang.String | toString()
return "Mpeg4 " + super.toString();
|