private void CreateTableOfContents() { try { // Just a guess at how many entries we'll need so the internal array need not resize very much // 400 bytes per frame is probably a good enough approximation. tableOfContents = new List <Mp3Index>((int)(mp3DataLength / 400)); Mp3Frame frame = null; totalSamples = 0; do { var index = new Mp3Index(); index.FilePosition = mp3Stream.Position; index.SamplePosition = totalSamples; frame = ReadNextFrame(false); if (frame != null) { totalSamples += frame.SampleCount; index.SampleCount = frame.SampleCount; index.ByteCount = (int)(mp3Stream.Position - index.FilePosition); tableOfContents.Add(index); } } while (frame != null); } catch (EndOfStreamException) { // not necessarily a problem } }
private void CreateTableOfContents() { try { // Just a guess at how many entries we'll need so the internal array need not resize very much // 400 bytes per frame is probably a good enough approximation. tableOfContents = new List<Mp3Index>((int) (mp3DataLength/400)); Mp3Frame frame = null; totalSamples = 0; do { var index = new Mp3Index(); index.FilePosition = mp3Stream.Position; index.SamplePosition = totalSamples; frame = ReadNextFrame(false); if (frame != null) { totalSamples += frame.SampleCount; index.SampleCount = frame.SampleCount; index.ByteCount = (int) (mp3Stream.Position - index.FilePosition); tableOfContents.Add(index); } } while (frame != null); } catch (EndOfStreamException) { // not necessarily a problem } }