| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
package com.drew.metadata.mp4; |
| 22 |
|
| 23 |
import com.drew.lang.Rational; |
| 24 |
import com.drew.lang.annotations.NotNull; |
| 25 |
import com.drew.metadata.TagDescriptor; |
| 26 |
|
| 27 |
import java.util.ArrayList; |
| 28 |
import java.util.Arrays; |
| 29 |
|
| 30 |
import static com.drew.metadata.mp4.Mp4Directory.*; |
| 31 |
|
| 32 |
public class Mp4Descriptor extends TagDescriptor<Mp4Directory> { |
| 33 |
|
| 34 |
public Mp4Descriptor(@NotNull Mp4Directory directory) |
| 35 |
{ |
| 36 |
super(directory); |
| 37 |
} |
| 38 |
|
| 39 |
@Override |
| 40 |
public String getDescription(int tagType) |
| 41 |
{ |
| 42 |
switch (tagType) { |
| 43 |
case TAG_MAJOR_BRAND: |
| 44 |
return getMajorBrandDescription(); |
| 45 |
case TAG_COMPATIBLE_BRANDS: |
| 46 |
return getCompatibleBrandsDescription(); |
| 47 |
case TAG_DURATION_SECONDS: |
| 48 |
return getDurationDescription(); |
| 49 |
default: |
| 50 |
return _directory.getString(tagType); |
| 51 |
} |
| 52 |
} |
| 53 |
|
| 54 |
private String getMajorBrandDescription() |
| 55 |
{ |
| 56 |
byte[] value = _directory.getByteArray(Mp4Directory.TAG_MAJOR_BRAND); |
| 57 |
if (value == null) |
| 58 |
return null; |
| 59 |
return Mp4Dictionary.lookup(TAG_MAJOR_BRAND, new String(value)); |
| 60 |
} |
| 61 |
|
| 62 |
private String getCompatibleBrandsDescription() |
| 63 |
{ |
| 64 |
String[] values = _directory.getStringArray(Mp4Directory.TAG_COMPATIBLE_BRANDS); |
| 65 |
if (values == null) |
| 66 |
return null; |
| 67 |
|
| 68 |
ArrayList<String> compatibleBrandsValues = new ArrayList<String>(); |
| 69 |
for (String value : values) { |
| 70 |
String compatibleBrandsValue = Mp4Dictionary.lookup(TAG_MAJOR_BRAND, value); |
| 71 |
compatibleBrandsValues.add(compatibleBrandsValue == null ? value : compatibleBrandsValue); |
| 72 |
} |
| 73 |
return Arrays.toString(compatibleBrandsValues.toArray()); |
| 74 |
} |
| 75 |
|
| 76 |
private String getDurationDescription() |
| 77 |
{ |
| 78 |
Rational duration = _directory.getRational(TAG_DURATION_SECONDS); |
| 79 |
if (duration == null) |
| 80 |
return null; |
| 81 |
|
| 82 |
double value = duration.doubleValue(); |
| 83 |
Integer hours = (int)(value / (Math.pow(60, 2))); |
| 84 |
Integer minutes = (int)((value / (Math.pow(60, 1))) - (hours * 60)); |
| 85 |
Integer seconds = (int)Math.ceil((value / (Math.pow(60, 0))) - (minutes * 60)); |
| 86 |
return String.format("%1$02d:%2$02d:%3$02d", hours, minutes, seconds); |
| 87 |
} |
| 88 |
} |