Make the grey shades on greyscale iPods a little darker, and the dark grey on H1x0...
[Rockbox.git] / songdbj / OggVorbisInfo.java
blobab07299e77a255127e8108dd7e9598932c91c36e
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.
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.
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 *----------------------------------------------------------------------
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;
33 import javax.sound.sampled.AudioFileFormat;
34 import javax.sound.sampled.AudioSystem;
35 import javax.sound.sampled.UnsupportedAudioFileException;
37 import org.tritonus.share.sampled.file.TAudioFileFormat;
39 /**
40 * This class gives information (audio format and comments) about Ogg Vorbis file or URL.
42 public class OggVorbisInfo implements TagInfo
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;
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();
66 /***
67 * Constructor.
69 public OggVorbisInfo()
71 super();
74 /**
75 * Load and parse Ogg Vorbis info from File.
76 * @param input
77 * @throws IOException
79 public void load(File input) throws IOException, UnsupportedAudioFileException
81 size = input.length();
82 location = input.getPath();
83 loadInfo(input);
86 /**
87 * Load and parse Ogg Vorbis info from URL.
88 * @param input
89 * @throws IOException
90 * @throws UnsupportedAudioFileException
92 public void load(URL input) throws IOException, UnsupportedAudioFileException
94 location = input.toString();
95 loadInfo(input);
98 /**
99 * Load and parse Ogg Vorbis info from InputStream.
100 * @param input
101 * @throws IOException
102 * @throws UnsupportedAudioFileException
104 public void load(InputStream input) throws IOException, UnsupportedAudioFileException
106 loadInfo(input);
110 * Load info from input stream.
111 * @param input
112 * @throws IOException
113 * @throws UnsupportedAudioFileException
115 protected void loadInfo(InputStream input) throws IOException, UnsupportedAudioFileException
117 AudioFileFormat aff = AudioSystem.getAudioFileFormat(input);
118 loadInfo(aff);
122 * Load Ogg Vorbis info from file.
123 * @param file
124 * @throws IOException
125 * @throws UnsupportedAudioFileException
127 protected void loadInfo(File file) throws IOException, UnsupportedAudioFileException
129 InputStream in = new BufferedInputStream(new FileInputStream(file));
130 loadInfo(in);
131 in.close();
135 * Load Ogg Vorbis info from URL.
136 * @param input
137 * @throws IOException
138 * @throws UnsupportedAudioFileException
140 protected void loadInfo(URL input) throws IOException, UnsupportedAudioFileException
142 AudioFileFormat aff = AudioSystem.getAudioFileFormat(input);
143 loadInfo(aff);
144 loadExtendedInfo(aff);
148 * Load info from AudioFileFormat.
149 * @param aff
150 * @throws UnsupportedAudioFileException
152 protected void loadInfo(AudioFileFormat aff) throws UnsupportedAudioFileException
154 String type = aff.getType().toString();
155 if (!type.equalsIgnoreCase("ogg")) throw new UnsupportedAudioFileException("Not Ogg Vorbis audio format");
156 if (aff instanceof TAudioFileFormat)
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");
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"))
181 track = Integer.parseInt((String)props.get("ogg.comment.track"));
183 catch (NumberFormatException e1)
185 // Not a number
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"));
195 * Load extended info from AudioFileFormat.
196 * @param aff
197 * @throws IOException
198 * @throws UnsupportedAudioFileException
200 protected void loadExtendedInfo(AudioFileFormat aff) throws IOException, UnsupportedAudioFileException
202 String type = aff.getType().toString();
203 if (!type.equalsIgnoreCase("ogg")) throw new UnsupportedAudioFileException("Not Ogg Vorbis audio format");
204 if (aff instanceof TAudioFileFormat)
206 Map props = ((TAudioFileFormat) aff).properties();
207 // How to load icecast meta data (if any) ??
211 public int getSerial()
213 return serial;
216 public int getChannels()
218 return channels;
221 public int getVersion()
223 return version;
226 public int getMinBitrate()
228 return minbitrate;
231 public int getMaxBitrate()
233 return maxbitrate;
236 public int getAverageBitrate()
238 return averagebitrate;
241 public long getSize()
243 return size;
246 public String getVendor()
248 return vendor;
251 public String getLocation()
253 return location;
256 /*-- TagInfo Implementation --*/
258 public int getSamplingRate()
260 return rate;
263 public int getBitRate()
265 return nominalbitrate;
268 public long getPlayTime()
270 return totalms;
273 public String getTitle()
275 return title;
278 public String getArtist()
280 return artist;
283 public String getAlbum()
285 return album;
288 public int getTrack()
290 return track;
293 public String getGenre()
295 return genre;
298 public Vector getComment()
300 return comments;
303 public String getYear()
305 return year;
308 public int getFirstFrameOffset() {
309 return 0;