1

I'm trying to figure out why NAudio is raising the following exception:

System.ArgumentOutOfRangeException was unhandled
Message: An unhandled exception of type 'System.ArgumentOutOfRangeException' 
occurred in NAudio.Vorbis.dll
Additional information: Specified argument out of range.

What I'm trying to do is creating a sort of fire and forget class for playing audios, here's the class:

public class FFSoundPlayer
{
    private readonly WaveOutEvent outputDevice;
    private WaveMixerStream32 mixer;
    private System.IO.Stream silenceStream;

    private FFSoundPlayer()
    {
        outputDevice = new WaveOutEvent();
        mixer = new WaveMixerStream32();

        System.Reflection.Assembly a = System.Reflection.Assembly.GetExecutingAssembly();
        silenceStream = a.GetManifestResourceStream("ProperPath.silence.ogg");
        VorbisWaveReader wv = new VorbisWaveReader(silenceStream);
        LoopWaveStream silence = new LoopWaveStream(wv);

        mixer.AddInputStream(silence);
        mixer.AutoStop = false;

        outputDevice.Init(mixer);

        outputDevice.Play();
    }

    public static FFSoundPlayer Instance = new FFSoundPlayer();

    public void AddWave(WaveStream wave)
    {
        mixer.AddInputStream(wave);
    }
}

LoopWaveStream is just a WaveStream that reset the position when it reaches the end of the stream.

After I send a few files to thru the AddWave method I get the exception from NAudio. Any ideas? Am I doing it the proper way?

Thanks

  • Don't know if it'll help but seems like it's raising the exception when the streams I added end – Christopher Jul 05 '16 at 09:52
  • Is there any InnerException? – Visual Vincent Jul 05 '16 at 10:06
  • @VisualVincent It doesn't let me see exception details, all I get is unfortunately what I've posted – Christopher Jul 05 '16 at 10:10
  • Okay? Well does it break on a specific line, or is it just thrown "in general"? Also have you checked so that you haven't set your IDE to always break on `ArgumentOutOfRangeException`? – Visual Vincent Jul 05 '16 at 10:12
  • @VisualVincent Since the exception comes from inside the vorbis dll I can not see the line and I'm not able to help you neither thru the call stack since it just show [external call] so I'd say it's "in general" – Christopher Jul 05 '16 at 10:15
  • Will check for exception settings but I'd like to know if it's me doing something wrong and then fix the code is causing the exception or if Naudio has gone crazy... the former probably anyway – Christopher Jul 05 '16 at 10:17
  • I'd say your best option right now would be to download the [**NAudio source code**](https://github.com/naudio/NAudio/tree/master/NAudio) and compile your own DLL from that. If you don't move that DLL anywhere (after compiling it) and reference it in your project, you should be able to see the source code when the application breaks. – Visual Vincent Jul 05 '16 at 10:22
  • So uninstall the packages from nuget and add the source code as project in my solution? – Christopher Jul 05 '16 at 10:24
  • Or as a standalone solution. When you're done testing you can install the NuGet packages again and remove your own reference. – Visual Vincent Jul 05 '16 at 10:26
  • Thanks a lot, I will try and update this post later – Christopher Jul 05 '16 at 10:28
  • NVorbis and NAudio.Vorbis are my projects. Exceptions from NVorbis will include the full stack trace if you can example the exception itself from within the debugger or the catch handler that logged it. If you can post the stack trace, I can take a look. Better yet, post it to the NAudio.Vorbis issues page on GitHub, then link to the issue from here. – ioctlLR Jul 08 '16 at 20:27

0 Answers0