ID3v22Handler v22 = null;
ID3v1Handler v1 = null;
LyricsHandler lyrics = null;
AudioFrame firstAudio = null;
TailStream tailStream = new TailStream(stream, 10240+128);
MpegStream mpegStream = new MpegStream(tailStream);
// ID3v2 tags live at the start of the file
// You can apparently have several different ID3 tag blocks
// So, keep going until we don't find any more
MP3Frame f;
while ((f = ID3v2Frame.createFrameIfPresent(mpegStream)) != null) {
if(f instanceof ID3v2Frame) {
ID3v2Frame id3F = (ID3v2Frame)f;
if (id3F.getMajorVersion() == 4) {
v24 = new ID3v24Handler(id3F);
} else if(id3F.getMajorVersion() == 3) {
v23 = new ID3v23Handler(id3F);
} else if(id3F.getMajorVersion() == 2) {
v22 = new ID3v22Handler(id3F);
}
}
}
// Now iterate over all audio frames in the file
AudioFrame frame = mpegStream.nextFrame();
float duration = 0;
while (frame != null)
{
duration += frame.getDuration();
if (firstAudio == null)
{
firstAudio = frame;
}
mpegStream.skipFrame();
frame = mpegStream.nextFrame();
}
// ID3v1 tags live at the end of the file
// Lyrics live just before ID3v1, at the end of the file
// Search for both (handlers seek to the end for us)
lyrics = new LyricsHandler(tailStream.getTail());
v1 = lyrics.id3v1;
// Go in order of preference
// Currently, that's newest to oldest
List<ID3Tags> tags = new ArrayList<ID3Tags>();