1

Resolved

Mp3FileReader - ArgumentOutOfRangeException - Non-negative number required

description

Hi there,

Just starting out with NAudio, but very hopeful it will make my coding life easier once I get past this issue.

I'm working on a WPF application (.net framework 4.5) that just needs to play any given MP3 file.

I'm using the following code pulled from a StackOverflow example (but I've also tried different variations, all with the same result):
using (var ms = File.OpenRead(audioFilePath))
using (var rdr = new Mp3FileReader(ms))   // exception is thrown here
using (var wavStream = WaveFormatConversionStream.CreatePcmStream(rdr))
using (var baStream = new BlockAlignReductionStream(wavStream))
using (var waveOut = new WaveOut(WaveCallbackInfo.FunctionCallback()))
{
    waveOut.Init(baStream);
    waveOut.Play();
    while (waveOut.PlaybackState == PlaybackState.Playing)
    {
        Thread.Sleep(100);
    }
}
When the Mp3FileReader constructor is called, I get the ArgumentOutOfRangeException and "Non-negative number required" message.

Any suggestions are appreciated, and please let me know if more information is required.
Thanks,
Geoffrey

comments

markheath wrote Sep 6, 2013 at 9:53 PM

most of that code is completely redundant (that StackOverflow example is a bad one!). You don't need the File.OpenRead, the WaveFOrmatConversionStream or the BlockAlignReductionStream. You should also not use Function callbacks. Use standard WaveOut with Window callbacks, or WaveOutEvent if you really must have a background thread for some reason.

Having said all that, it might be some kind of issue with your MP3 file. Are you able to share an MP3 file that has this issue?

gopherr127 wrote Sep 6, 2013 at 10:28 PM

You are correct, sir. It was the file itself.

Also, I've reverted back to the more recently-suggested code; what I posted was just my last attempt before posting my question.

Thanks for your quick response!