Mp4GenreFieldpublic class Mp4GenreField extends Mp4TagTextNumberField Represents the Genre field , when user has selected from the set list of genres
This class allows you to retrieve either the internal genreid, or the display value |
Constructors Summary |
---|
public Mp4GenreField(String id, ByteBuffer data)
super(id, data);
| public Mp4GenreField(String genreId)Construct genre, if cant find match just default to first genre
super(Mp4FieldKey.GENRE.getFieldName(), genreId);
//Is it an id
try
{
short genreVal = Short.parseShort(genreId);
if ((genreVal - 1) <= GenreTypes.getMaxStandardGenreId())
{
numbers = new ArrayList<Short>();
numbers.add(genreVal);
return;
}
//Default
numbers = new ArrayList<Short>();
numbers.add((short) (1));
return;
}
catch (NumberFormatException nfe)
{
//Do Nothing test as String instead
}
//Is it the String value ?
Integer id3GenreId = GenreTypes.getInstanceOf().getIdForValue(genreId);
if (id3GenreId != null)
{
if (id3GenreId <= GenreTypes.getMaxStandardGenreId())
{
numbers = new ArrayList<Short>();
numbers.add((short) (id3GenreId + 1));
return;
}
}
numbers = new ArrayList<Short>();
numbers.add((short) (1));
|
Methods Summary |
---|
protected void | build(java.nio.ByteBuffer data)
//Data actually contains a 'Data' Box so process data using this
Mp4BoxHeader header = new Mp4BoxHeader(data);
Mp4DataBox databox = new Mp4DataBox(header, data);
dataSize = header.getDataLength();
numbers = databox.getNumbers();
int genreId = numbers.get(0);
//Get value, we have to adjust index by one because iTunes labels from one instead of zero
content = GenreTypes.getInstanceOf().getValueForId(genreId - 1);
//Some apps set genre to invalid value, we dont disguise this by setting content to empty string we leave
//as null so apps can handle if they wish, but we do display a warning to make them aware.
if (content == null)
{
logger.warning(ErrorMessage.MP4_GENRE_OUT_OF_RANGE.getMsg(genreId));
}
| public static boolean | isValidGenre(java.lang.String genreId)Precheck to see if the value is a valid genre or whether you should use a custom genre.
//Is it an id (within old id3 range)
try
{
short genreVal = Short.parseShort(genreId);
if ((genreVal - 1) <= GenreTypes.getMaxStandardGenreId())
{
return true;
}
}
catch (NumberFormatException nfe)
{
//Do Nothing test as String instead
}
//Is it the String value ?
Integer id3GenreId = GenreTypes.getInstanceOf().getIdForValue(genreId);
if (id3GenreId != null)
{
if (id3GenreId <= GenreTypes.getMaxStandardGenreId())
{
return true;
}
}
return false;
|
|