diff options
Diffstat (limited to 'songdbj/OggVorbisInfo.java')
-rw-r--r-- | songdbj/OggVorbisInfo.java | 311 |
1 files changed, 0 insertions, 311 deletions
diff --git a/songdbj/OggVorbisInfo.java b/songdbj/OggVorbisInfo.java deleted file mode 100644 index ab07299e77..0000000000 --- a/songdbj/OggVorbisInfo.java +++ /dev/null | |||
@@ -1,311 +0,0 @@ | |||
1 | /* | ||
2 | * OggVorbisInfo. | ||
3 | * | ||
4 | * JavaZOOM : jlgui@javazoom.net | ||
5 | * http://www.javazoom.net | ||
6 | * | ||
7 | *----------------------------------------------------------------------- | ||
8 | * This program is free software; you can redistribute it and/or modify | ||
9 | * it under the terms of the GNU Library General Public License as published | ||
10 | * by the Free Software Foundation; either version 2 of the License, or | ||
11 | * (at your option) any later version. | ||
12 | * | ||
13 | * This program is distributed in the hope that it will be useful, | ||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
16 | * GNU Library General Public License for more details. | ||
17 | * | ||
18 | * You should have received a copy of the GNU Library General Public | ||
19 | * License along with this program; if not, write to the Free Software | ||
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
21 | *---------------------------------------------------------------------- | ||
22 | */ | ||
23 | |||
24 | import java.io.File; | ||
25 | import java.io.IOException; | ||
26 | import java.io.InputStream; | ||
27 | import java.io.FileInputStream; | ||
28 | import java.io.BufferedInputStream; | ||
29 | import java.net.URL; | ||
30 | import java.util.Map; | ||
31 | import java.util.Vector; | ||
32 | |||
33 | import javax.sound.sampled.AudioFileFormat; | ||
34 | import javax.sound.sampled.AudioSystem; | ||
35 | import javax.sound.sampled.UnsupportedAudioFileException; | ||
36 | |||
37 | import org.tritonus.share.sampled.file.TAudioFileFormat; | ||
38 | |||
39 | /** | ||
40 | * This class gives information (audio format and comments) about Ogg Vorbis file or URL. | ||
41 | */ | ||
42 | public class OggVorbisInfo implements TagInfo | ||
43 | { | ||
44 | protected int serial = 0; | ||
45 | protected int channels = 0; | ||
46 | protected int version = 0; | ||
47 | protected int rate = 0; | ||
48 | protected int minbitrate = 0; | ||
49 | protected int maxbitrate = 0; | ||
50 | protected int averagebitrate = 0; | ||
51 | protected int nominalbitrate = 0; | ||
52 | protected long totalms = 0; | ||
53 | protected String vendor = ""; | ||
54 | protected String location = null; | ||
55 | |||
56 | protected long size = 0; | ||
57 | protected int track = -1; | ||
58 | protected String year = null; | ||
59 | protected String genre = null; | ||
60 | protected String title = null; | ||
61 | protected String artist = null; | ||
62 | protected String album = null; | ||
63 | protected Vector comments = new Vector(); | ||
64 | |||
65 | |||
66 | /*** | ||
67 | * Constructor. | ||
68 | */ | ||
69 | public OggVorbisInfo() | ||
70 | { | ||
71 | super(); | ||
72 | } | ||
73 | |||
74 | /** | ||
75 | * Load and parse Ogg Vorbis info from File. | ||
76 | * @param input | ||
77 | * @throws IOException | ||
78 | */ | ||
79 | public void load(File input) throws IOException, UnsupportedAudioFileException | ||
80 | { | ||
81 | size = input.length(); | ||
82 | location = input.getPath(); | ||
83 | loadInfo(input); | ||
84 | } | ||
85 | |||
86 | /** | ||
87 | * Load and parse Ogg Vorbis info from URL. | ||
88 | * @param input | ||
89 | * @throws IOException | ||
90 | * @throws UnsupportedAudioFileException | ||
91 | */ | ||
92 | public void load(URL input) throws IOException, UnsupportedAudioFileException | ||
93 | { | ||
94 | location = input.toString(); | ||
95 | loadInfo(input); | ||
96 | } | ||
97 | |||
98 | /** | ||
99 | * Load and parse Ogg Vorbis info from InputStream. | ||
100 | * @param input | ||
101 | * @throws IOException | ||
102 | * @throws UnsupportedAudioFileException | ||
103 | */ | ||
104 | public void load(InputStream input) throws IOException, UnsupportedAudioFileException | ||
105 | { | ||
106 | loadInfo(input); | ||
107 | } | ||
108 | |||
109 | /** | ||
110 | * Load info from input stream. | ||
111 | * @param input | ||
112 | * @throws IOException | ||
113 | * @throws UnsupportedAudioFileException | ||
114 | */ | ||
115 | protected void loadInfo(InputStream input) throws IOException, UnsupportedAudioFileException | ||
116 | { | ||
117 | AudioFileFormat aff = AudioSystem.getAudioFileFormat(input); | ||
118 | loadInfo(aff); | ||
119 | } | ||
120 | |||
121 | /** | ||
122 | * Load Ogg Vorbis info from file. | ||
123 | * @param file | ||
124 | * @throws IOException | ||
125 | * @throws UnsupportedAudioFileException | ||
126 | */ | ||
127 | protected void loadInfo(File file) throws IOException, UnsupportedAudioFileException | ||
128 | { | ||
129 | InputStream in = new BufferedInputStream(new FileInputStream(file)); | ||
130 | loadInfo(in); | ||
131 | in.close(); | ||
132 | } | ||
133 | |||
134 | /** | ||
135 | * Load Ogg Vorbis info from URL. | ||
136 | * @param input | ||
137 | * @throws IOException | ||
138 | * @throws UnsupportedAudioFileException | ||
139 | */ | ||
140 | protected void loadInfo(URL input) throws IOException, UnsupportedAudioFileException | ||
141 | { | ||
142 | AudioFileFormat aff = AudioSystem.getAudioFileFormat(input); | ||
143 | loadInfo(aff); | ||
144 | loadExtendedInfo(aff); | ||
145 | } | ||
146 | |||
147 | /** | ||
148 | * Load info from AudioFileFormat. | ||
149 | * @param aff | ||
150 | * @throws UnsupportedAudioFileException | ||
151 | */ | ||
152 | protected void loadInfo(AudioFileFormat aff) throws UnsupportedAudioFileException | ||
153 | { | ||
154 | String type = aff.getType().toString(); | ||
155 | if (!type.equalsIgnoreCase("ogg")) throw new UnsupportedAudioFileException("Not Ogg Vorbis audio format"); | ||
156 | if (aff instanceof TAudioFileFormat) | ||
157 | { | ||
158 | Map props = ((TAudioFileFormat) aff).properties(); | ||
159 | if (props.containsKey("ogg.channels")) channels = ((Integer)props.get("ogg.channels")).intValue(); | ||
160 | if (props.containsKey("ogg.frequency.hz")) rate = ((Integer)props.get("ogg.frequency.hz")).intValue(); | ||
161 | if (props.containsKey("ogg.bitrate.nominal.bps")) nominalbitrate = ((Integer)props.get("ogg.bitrate.nominal.bps")).intValue(); | ||
162 | averagebitrate = nominalbitrate; | ||
163 | if (props.containsKey("ogg.bitrate.max.bps")) maxbitrate = ((Integer)props.get("ogg.bitrate.max.bps")).intValue(); | ||
164 | if (props.containsKey("ogg.bitrate.min.bps")) minbitrate = ((Integer)props.get("ogg.bitrate.min.bps")).intValue(); | ||
165 | if (props.containsKey("ogg.version")) version = ((Integer)props.get("ogg.version")).intValue(); | ||
166 | if (props.containsKey("ogg.serial")) serial = ((Integer)props.get("ogg.serial")).intValue(); | ||
167 | if (props.containsKey("ogg.comment.encodedby")) vendor = (String)props.get("ogg.comment.encodedby"); | ||
168 | |||
169 | if (props.containsKey("copyright")) comments.add((String)props.get("copyright")); | ||
170 | if (props.containsKey("title")) title = (String)props.get("title"); | ||
171 | if (props.containsKey("author")) artist = (String)props.get("author"); | ||
172 | if (props.containsKey("album")) album = (String)props.get("album"); | ||
173 | if (props.containsKey("date")) year = (String)props.get("date"); | ||
174 | if (props.containsKey("comment")) comments.add((String)props.get("comment")); | ||
175 | if (props.containsKey("duration")) totalms = (long) Math.round((((Long)props.get("duration")).longValue())/1000000); | ||
176 | if (props.containsKey("ogg.comment.genre")) genre = (String)props.get("ogg.comment.genre"); | ||
177 | if (props.containsKey("ogg.comment.track")) | ||
178 | { | ||
179 | try | ||
180 | { | ||
181 | track = Integer.parseInt((String)props.get("ogg.comment.track")); | ||
182 | } | ||
183 | catch (NumberFormatException e1) | ||
184 | { | ||
185 | // Not a number | ||
186 | } | ||
187 | } | ||
188 | if (props.containsKey("ogg.comment.ext.1")) comments.add((String)props.get("ogg.comment.ext.1")); | ||
189 | if (props.containsKey("ogg.comment.ext.2")) comments.add((String)props.get("ogg.comment.ext.2")); | ||
190 | if (props.containsKey("ogg.comment.ext.3")) comments.add((String)props.get("ogg.comment.ext.3")); | ||
191 | } | ||
192 | } | ||
193 | |||
194 | /** | ||
195 | * Load extended info from AudioFileFormat. | ||
196 | * @param aff | ||
197 | * @throws IOException | ||
198 | * @throws UnsupportedAudioFileException | ||
199 | */ | ||
200 | protected void loadExtendedInfo(AudioFileFormat aff) throws IOException, UnsupportedAudioFileException | ||
201 | { | ||
202 | String type = aff.getType().toString(); | ||
203 | if (!type.equalsIgnoreCase("ogg")) throw new UnsupportedAudioFileException("Not Ogg Vorbis audio format"); | ||
204 | if (aff instanceof TAudioFileFormat) | ||
205 | { | ||
206 | Map props = ((TAudioFileFormat) aff).properties(); | ||
207 | // How to load icecast meta data (if any) ?? | ||
208 | } | ||
209 | } | ||
210 | |||
211 | public int getSerial() | ||
212 | { | ||
213 | return serial; | ||
214 | } | ||
215 | |||
216 | public int getChannels() | ||
217 | { | ||
218 | return channels; | ||
219 | } | ||
220 | |||
221 | public int getVersion() | ||
222 | { | ||
223 | return version; | ||
224 | } | ||
225 | |||
226 | public int getMinBitrate() | ||
227 | { | ||
228 | return minbitrate; | ||
229 | } | ||
230 | |||
231 | public int getMaxBitrate() | ||
232 | { | ||
233 | return maxbitrate; | ||
234 | } | ||
235 | |||
236 | public int getAverageBitrate() | ||
237 | { | ||
238 | return averagebitrate; | ||
239 | } | ||
240 | |||
241 | public long getSize() | ||
242 | { | ||
243 | return size; | ||
244 | } | ||
245 | |||
246 | public String getVendor() | ||
247 | { | ||
248 | return vendor; | ||
249 | } | ||
250 | |||
251 | public String getLocation() | ||
252 | { | ||
253 | return location; | ||
254 | } | ||
255 | |||
256 | /*-- TagInfo Implementation --*/ | ||
257 | |||
258 | public int getSamplingRate() | ||
259 | { | ||
260 | return rate; | ||
261 | } | ||
262 | |||
263 | public int getBitRate() | ||
264 | { | ||
265 | return nominalbitrate; | ||
266 | } | ||
267 | |||
268 | public long getPlayTime() | ||
269 | { | ||
270 | return totalms; | ||
271 | } | ||
272 | |||
273 | public String getTitle() | ||
274 | { | ||
275 | return title; | ||
276 | } | ||
277 | |||
278 | public String getArtist() | ||
279 | { | ||
280 | return artist; | ||
281 | } | ||
282 | |||
283 | public String getAlbum() | ||
284 | { | ||
285 | return album; | ||
286 | } | ||
287 | |||
288 | public int getTrack() | ||
289 | { | ||
290 | return track; | ||
291 | } | ||
292 | |||
293 | public String getGenre() | ||
294 | { | ||
295 | return genre; | ||
296 | } | ||
297 | |||
298 | public Vector getComment() | ||
299 | { | ||
300 | return comments; | ||
301 | } | ||
302 | |||
303 | public String getYear() | ||
304 | { | ||
305 | return year; | ||
306 | } | ||
307 | |||
308 | public int getFirstFrameOffset() { | ||
309 | return 0; | ||
310 | } | ||
311 | } \ No newline at end of file | ||