// --------------------------------------------------------------------------- private void ReadFramesNew(String FileName, ref TagInfo Tag) { FrameHeaderNew Frame = new FrameHeaderNew(); FileStream fs = null; BinaryReader SourceFile = null; char[] Data; long DataPosition; long DataSize; // Get information from frames (ID3v2.3.x & ID3v2.4.x) try { // Set read-access, open file fs = new FileStream(FileName, FileMode.Open, FileAccess.Read); SourceFile = new BinaryReader(fs); fs.Seek(10, SeekOrigin.Begin); while ( (fs.Position < GetTagSize(Tag)) && (fs.Position < fs.Length) ) { //Array.Clear(Data,0,Data.Length); // Read frame header and check frame ID Frame.ID = SourceFile.ReadChars(4); Frame.Size = SourceFile.ReadInt32(); Frame.Flags = SourceFile.ReadUInt16(); if ( ! ( Char.IsLetter(Frame.ID[0]) && Char.IsUpper(Frame.ID[0]) ) ) break; // Note data position and determine significant data size DataPosition = fs.Position; if ( Swap32(Frame.Size) > 500 ) DataSize = 500; else DataSize = Swap32(Frame.Size); byte[] bData = new byte[DataSize]; Data = new char[DataSize]; // Read frame data and set tag item if frame supported bData = SourceFile.ReadBytes((int)DataSize); Array.Copy(bData,Data,bData.Length); if ( 32768 != (Frame.Flags & 32768) ) SetTagItem(new String(Frame.ID), new String(Data), ref Tag); // Wipe out \0's to avoid string cuts fs.Seek(DataPosition + Swap32(Frame.Size), SeekOrigin.Begin); } } catch (Exception e) { System.Console.WriteLine(e.Message); System.Console.WriteLine(e.StackTrace); } if (SourceFile != null) SourceFile.Close(); if (fs != null) fs.Close(); }
// --------------------------------------------------------------------------- private void ReadFramesNew(String FileName, ref TagInfo Tag) { FrameHeaderNew Frame = new FrameHeaderNew(); FileStream fs = null; BinaryReader SourceFile = null; char[] Data; long DataPosition; long DataSize; // Get information from frames (ID3v2.3.x & ID3v2.4.x) try { // Set read-access, open file fs = new FileStream(FileName, FileMode.Open, FileAccess.Read); SourceFile = new BinaryReader(fs); fs.Seek(10, SeekOrigin.Begin); while ((fs.Position < GetTagSize(Tag)) && (fs.Position < fs.Length)) { //Array.Clear(Data,0,Data.Length); // Read frame header and check frame ID Frame.ID = SourceFile.ReadChars(4); Frame.Size = SourceFile.ReadInt32(); Frame.Flags = SourceFile.ReadUInt16(); if (!(Char.IsLetter(Frame.ID[0]) && Char.IsUpper(Frame.ID[0]))) { break; } // Note data position and determine significant data size DataPosition = fs.Position; if (Swap32(Frame.Size) > 500) { DataSize = 500; } else { DataSize = Swap32(Frame.Size); } byte[] bData = new byte[DataSize]; Data = new char[DataSize]; // Read frame data and set tag item if frame supported bData = SourceFile.ReadBytes((int)DataSize); Array.Copy(bData, Data, bData.Length); if (32768 != (Frame.Flags & 32768)) { SetTagItem(new String(Frame.ID), new String(Data), ref Tag); // Wipe out \0's to avoid string cuts } fs.Seek(DataPosition + Swap32(Frame.Size), SeekOrigin.Begin); } } catch (Exception e) { System.Console.WriteLine(e.Message); System.Console.WriteLine(e.StackTrace); } if (SourceFile != null) { SourceFile.Close(); } if (fs != null) { fs.Close(); } }