private ID3v2MajorVersion Read(Stream stream, FrameParserFactory frameParserFactory)
{
TagHeader header=TagHeader.FromStream(stream);
if(header==null)
{
throw new FatalException("No ID3 v2 tag is attached to this file.");
}
if(!Enum.IsDefined(typeof(ID3v2MajorVersion),header.MajorVersion) )
{
throw new FatalException("Reading this major version of ID3 v2 is not supported.");
}
if(header.Flags!=TagHeaderFlags.None)
{
throw new FatalException("Reading tags with with any set flags are not supported in this version.");
}
long startingPosition=stream.Position;
while(stream.Position-startingPosition <header.TagSize)
{
long beginPosition=stream.Position;
Frame frame=null;
string frameID="";
try
{
frame=FrameParser.Parse(stream, (ID3v2MajorVersion)header.MajorVersion, frameParserFactory, out frameID);
if(frame==null)
{
break;
}
}
catch(NonFatalException ex)
{
RaiseReadingWarning(ex,frameID);
}
if(beginPosition==stream.Position) // Probably stuck in an infinite loop because of corrupt data in file. Exit the loop.
{
break;
}
if(frame!=null)
{
this.Frames.Add(frame);
}
}
return (ID3v2MajorVersion)header.MajorVersion;
}