This project has moved and is read-only. For the latest updates, please go here.
1
Vote

NAudio freezes on one specific mp3 file

description

NAudio is freezing on one specific mp3 file. All other files play ok. This same mp3 file plays fine in Windows Media Player. However, in NAudio, this one specific file freezes towards the end of the file. I have tried two versions of NAudio : 1.7.3 and 1.8.0 (latest) and both have the same freezing issue. I can provide the MP3 file for developer testing. Thank you.

file attachments

comments

markheath wrote Feb 25 at 9:39 AM

Hi, thanks for reporting this issue.

You're welcome to provide an MP3 for testing, but I can't make any promises about when I'll have time to investigate this specific issue.

As a workaround you could try using MediaFoundationReader instead which might be more reliable.

adielglez wrote Feb 28 at 6:42 PM

Hi thank you for your message. Unfortunately we cannot afford to switch to MediaFoundationReader at this point in development and usage of NAudio. If you can please when you have an opportunity, I am attaching the actual sample mp3 file. This file plays all the way to the end with no problems using Windows Media Player. However, with NAudio, it NAudio freezes almost at the end of the file. I would really appreciate your concern to this. Thank You.

markheath wrote Mar 2 at 7:19 PM

If you play this in the NAudio Demo app it seems you'll find that there is no problem playing it to the same point that Windows Media Player does. The only issue I noticed is that NAudio does not accurately work out how far through we are, probably due to changes to bitrate maybe. So long as you wait until WaveOut PlaybackStopped event is fired, you should hear everything.

adielglez wrote Mar 3 at 4:42 PM

Thanks. It looks like it is something that should be corrected. I was able to do a workaround with your suggestion by also checking if playbackstate is stopped as you mentioned:

private bool endOfStream()
    {

        try
        {
            // To check for end of file, check stream position
            // In addition, also check PlaybackState 
            // Since NAudio does not accurately work out how far through we are, probably due to changes to bitrate
            if (fileWaveStream.Position >= fileWaveStream.Length || waveOut.PlaybackState == PlaybackState.Stopped)
            {
                return true;
            }
            else
            {
                return false;
            }

        }
        catch (Exception ex)
        {
            return true; // if we have an error mark as end of stream true
        }

    }

markheath wrote Mar 3 at 5:24 PM

NAudio works out the length of an MP3 file by examining each frame and calculating how many samples it ought to decompress into. But sometimes (maybe due to corruption) that is wrong. Can be very hard to track down, so the solution you show is the right way to work around this.