FileDocCategorySizeDatePackage
Mp4TrackField.javaAPI DocJaudiotagger 2.0.45762Tue Aug 02 17:09:54 BST 2011org.jaudiotagger.tag.mp4.field

Mp4TrackField

public class Mp4TrackField extends Mp4TagTextNumberField
Represents the Track No field

There are a number of reserved fields making matters more complicated Reserved:2 bytes Track Number:2 bytes No of Tracks:2 bytes (or zero if not known) PlayListTitleReserved: 1 byte playtitlenameReserved:0 bytes

Fields Summary
private static final int
NONE_VALUE_INDEX
private static final int
TRACK_NO_INDEX
private static final int
TRACK_TOTAL_INDEX
private static final int
NONE_END_VALUE_INDEX
Constructors Summary
public Mp4TrackField(String trackValue)
Create new Track Field parsing the String for the trackno/total

param
trackValue
throws
org.jaudiotagger.tag.FieldDataInvalidException


                       
        
    
        super(Mp4FieldKey.TRACK.getFieldName(), trackValue);

        numbers = new ArrayList<Short>();
        numbers.add(new Short("0"));

        String values[] = trackValue.split("/");
        switch (values.length)
        {
            case 1:
                try
                {
                    numbers.add(Short.parseShort(values[0]));
                }
                catch (NumberFormatException nfe)
                {
                    throw new FieldDataInvalidException("Value of:" + values[0] + " is invalid for field:" + id);
                }
                numbers.add(new Short("0"));
                numbers.add(new Short("0"));
                break;

            case 2:
                try
                {
                    numbers.add(Short.parseShort(values[0]));
                }
                catch (NumberFormatException nfe)
                {
                    throw new FieldDataInvalidException("Value of:" + values[0] + " is invalid for field:" + id);
                }
                try
                {
                    numbers.add(Short.parseShort(values[1]));
                }
                catch (NumberFormatException nfe)
                {
                    throw new FieldDataInvalidException("Value of:" + values[1] + " is invalid for field:" + id);
                }
                numbers.add(new Short("0"));
                break;

            default:
                throw new FieldDataInvalidException("Value is invalid for field:" + id);
        }
    
public Mp4TrackField(int trackNo)
Create new Track Field with only track No

param
trackNo


        super(Mp4FieldKey.TRACK.getFieldName(), String.valueOf(trackNo));
        numbers = new ArrayList<Short>();
        numbers.add(new Short("0"));
        numbers.add((short) trackNo);
        numbers.add(new Short("0"));
        numbers.add(new Short("0"));
    
public Mp4TrackField(int trackNo, int total)
Create new Track Field with track No and total tracks

param
trackNo
param
total

        super(Mp4FieldKey.TRACK.getFieldName(), String.valueOf(trackNo));
        numbers = new ArrayList<Short>();
        numbers.add(new Short("0"));
        numbers.add((short) trackNo);
        numbers.add((short) total);
        numbers.add(new Short("0"));
    
public Mp4TrackField(String id, ByteBuffer data)
Construct from filedata

param
id
param
data
throws
UnsupportedEncodingException

        super(id, data);
    
Methods Summary
protected voidbuild(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();
        //Track number always hold three values, we can discard the first one, the second one is the track no
        //and the third is the total no of tracks so only use if not zero
        StringBuffer sb = new StringBuffer();
        if(numbers!=null)
        {
            if ((numbers.size() > TRACK_NO_INDEX) && (numbers.get(TRACK_NO_INDEX) > 0))
            {
                sb.append(numbers.get(TRACK_NO_INDEX));
            }
            if ((numbers.size() > TRACK_TOTAL_INDEX) && (numbers.get(TRACK_TOTAL_INDEX) > 0))
            {
                sb.append("/").append(numbers.get(TRACK_TOTAL_INDEX));
            }
        }
        content = sb.toString();
    
public java.lang.ShortgetTrackNo()

return

        return numbers.get(TRACK_NO_INDEX);
    
public java.lang.ShortgetTrackTotal()

return

        if(numbers.size()<=TRACK_TOTAL_INDEX)
        {
            return 0;
        }
        return numbers.get(TRACK_TOTAL_INDEX);
    
public voidsetTrackNo(int trackNo)
Set Track No

param
trackNo

        numbers.set(TRACK_NO_INDEX, (short) trackNo);
    
public voidsetTrackTotal(int trackTotal)
Set total number of tracks

param
trackTotal

       numbers.set(TRACK_TOTAL_INDEX, (short) trackTotal);