Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReadNextFrame() method do not change stream position #161

Closed
patachi opened this issue Jan 30, 2017 · 3 comments
Closed

ReadNextFrame() method do not change stream position #161

patachi opened this issue Jan 30, 2017 · 3 comments

Comments

@patachi
Copy link

patachi commented Jan 30, 2017

hmm ... maybe there should be another approach to achieve this.
in this code reader.CurrentTime has fixed value .


public static byte[] CropMp3(Mp3CropInfo_DTO cropInfo, bool includeId3Tags = false)
        {
            using (var source = new MemoryStream(cropInfo.Mp3File))
            using (var reader = new Mp3FileReader(source))
            using (var writer = new MemoryStream())
            {
                //Extract ID3 tags
                if (reader.Id3v2Tag != null && includeId3Tags)
                {
                    writer.Write(reader.Id3v2Tag.RawData, 0, reader.Id3v2Tag.RawData.Length);
                }
                //Optional :/
                //reader.CurrentTime = cropInfo.StartTime;
                Mp3Frame frame;
                while (reader.CurrentTime.CompareTo(cropInfo.EndTime) <= 0 && (frame = reader.ReadNextFrame()) != null)
                {
                    if (reader.CurrentTime.CompareTo(cropInfo.StartTime) >= 0)
                    {
                        writer.Write(frame.RawData, 0, frame.RawData.Length);
                    }
                }
                writer.Flush();
                return writer.ToArray();
            }
        }
@markheath
Copy link
Contributor

thanks for the reminder, have been meaning to sort that out for a while

@philkild
Copy link

philkild commented Jul 3, 2017

@markheath could you publish a new NuGet with this fix included?

@markheath
Copy link
Contributor

yes, have just pushed 1.8.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants