1 | package org.farng.mp3.object; |
2 | |
3 | /** |
4 | * ID3v2 and Lyrics3v2 tags have individual fields <code>AbstractMP3Fragment</code>s Then each fragment is broken down |
5 | * in to individual <code>AbstractMP3Object</code>s |
6 | * |
7 | * @author Eric Farng |
8 | * @version $Revision: 1.5 $ |
9 | */ |
10 | public class ObjectLyrics3TimeStamp extends AbstractMP3Object { |
11 | |
12 | private long minute = 0; |
13 | private long second = 0; |
14 | private byte timeStampFormat = 0; |
15 | |
16 | /** |
17 | * Creates a new ObjectLyrics3TimeStamp object. |
18 | */ |
19 | public ObjectLyrics3TimeStamp(final String identifier) { |
20 | this.identifier = identifier; |
21 | } |
22 | |
23 | /** |
24 | * Creates a new ObjectLyrics3TimeStamp object. |
25 | */ |
26 | public ObjectLyrics3TimeStamp(final ObjectLyrics3TimeStamp copyObject) { |
27 | super(copyObject); |
28 | this.minute = copyObject.minute; |
29 | this.second = copyObject.second; |
30 | } |
31 | |
32 | public void setMinute(final long minute) { |
33 | this.minute = minute; |
34 | } |
35 | |
36 | public long getMinute() { |
37 | return this.minute; |
38 | } |
39 | |
40 | public byte getTimeStampFormat() { |
41 | return this.timeStampFormat; |
42 | } |
43 | |
44 | public void setTimeStampFormat(final byte timeStampFormat) { |
45 | this.timeStampFormat = timeStampFormat; |
46 | } |
47 | |
48 | public void setSecond(final long second) { |
49 | this.second = second; |
50 | } |
51 | |
52 | public long getSecond() { |
53 | return this.second; |
54 | } |
55 | |
56 | public int getSize() { |
57 | return 7; |
58 | } |
59 | |
60 | /** |
61 | * Creates a new ObjectLyrics3TimeStamp object. |
62 | */ |
63 | public void setTimeStamp(long timeStamp, final byte timeStampFormat) { |
64 | // todo convert both types of formats |
65 | timeStamp = timeStamp / 1000; |
66 | this.minute = timeStamp / 60; |
67 | this.second = timeStamp % 60; |
68 | this.timeStampFormat = timeStampFormat; |
69 | } |
70 | |
71 | public boolean equals(final Object obj) { |
72 | if ((obj instanceof ObjectLyrics3TimeStamp) == false) { |
73 | return false; |
74 | } |
75 | final ObjectLyrics3TimeStamp objectLyrics3TimeStamp = (ObjectLyrics3TimeStamp) obj; |
76 | if (this.minute != objectLyrics3TimeStamp.minute) { |
77 | return false; |
78 | } |
79 | if (this.second != objectLyrics3TimeStamp.second) { |
80 | return false; |
81 | } |
82 | return super.equals(obj); |
83 | } |
84 | |
85 | public void readString(String timeStamp, final int offset) { |
86 | if (timeStamp == null) { |
87 | throw new NullPointerException("Image is null"); |
88 | } |
89 | if ((offset < 0) || (offset >= timeStamp.length())) { |
90 | throw new IndexOutOfBoundsException("Offset to timeStamp is out of bounds: offset = " + |
91 | offset + |
92 | ", timeStamp.length()" + |
93 | timeStamp.length()); |
94 | } |
95 | timeStamp = timeStamp.substring(offset); |
96 | if (timeStamp.length() == 7) { |
97 | this.minute = Integer.parseInt(timeStamp.substring(1, 3)); |
98 | this.second = Integer.parseInt(timeStamp.substring(4, 6)); |
99 | } else { |
100 | this.minute = 0; |
101 | this.second = 0; |
102 | } |
103 | } |
104 | |
105 | public String toString() { |
106 | return writeString(); |
107 | } |
108 | |
109 | public String writeString() { |
110 | String str; |
111 | str = "["; |
112 | if (this.minute < 0) { |
113 | str += "00"; |
114 | } else { |
115 | if (this.minute < 10) { |
116 | str += '0'; |
117 | } |
118 | str += Long.toString(this.minute); |
119 | } |
120 | str += ':'; |
121 | if (this.second < 0) { |
122 | str += "00"; |
123 | } else { |
124 | if (this.second < 10) { |
125 | str += '0'; |
126 | } |
127 | str += Long.toString(this.second); |
128 | } |
129 | str += ']'; |
130 | return str; |
131 | } |
132 | } |