This project has moved. For the latest updates, please go here.

nodriver calling waveInPrepareHeader

Apr 5, 2011 at 11:57 AM

Hello, thanks for an awesome library. I'm using it in my open source project iSpy (camera security software) - I have a problem where if I unplug the USB microphone whilst NAudio is monitoring it I get an exception ("nodriver calling waveInPrepareHeader") - which is fine, but I can't see a way to catch and deal with the error... any ideas?

Apr 6, 2011 at 2:03 PM

anybody there? :(

Coordinator
Apr 6, 2011 at 3:17 PM

can you catch it in the application's unhandled exception handler?

It is quite hard to deal with exceptions in callbacks as depending on your callback model you could be on a thread created by the audio device driver

Mark

Apr 7, 2011 at 1:58 AM

hey mark, yes it is running on a different thread, would be good if there could be an error event I could attach to to process the error.. something like:

waveIn.Error += new EventHandler(waveIn_Error);


I can catch the error in the application at the program level but as ispy allows adding of multiple microphones i then have no way of knowing which one threw it...

Thanks!

Sean

Coordinator
Apr 9, 2011 at 7:21 AM

It's a good, although events like that can be a real pain to implement for all possible implementations of IWaveIn due to the wide variety of threading models available. I'll have a think about how it might be done in a future version. You can always take a copy of WaveIn and implement your own in the meantime.

Mark

Mar 6, 2012 at 7:57 PM

I'm running into the same problem.

I'm using your (just added) WaveInEvent, and when I pull the plug of the Mic while recording I get a MMException "NoDriver" in WaveInPrepareHeader called in WaveInBuffer::Reuse().

This exception is thrown in WaveInEvent's recording-thread so there is no way for me to catch it.
Letting it escalate to the application's Unhandled Exception handler is of no use since there's no way to keep running the program in that case - it has to exit.

Am I correct in assuming there is no handling for unforeseen events like unplugged devices ?
Anyway, I'm fixing it locally by modifying the WaveInEvent's recording thread to handle the exception by flipping 'recording' to false, but I'd rather not work with locally modified versions of NAudio of course ;)

Cheers,

Lennart.

Coordinator
Mar 6, 2012 at 7:59 PM

My plan for the future (hopefully near future) is for the PlaybackStopped and RecordingStopped events to include a possible Exception. Then all IWavePlayer and IWaveIn implementations have an easy way of reporting exceptions back to the user.

Mar 7, 2012 at 2:48 AM

FYI I am successfully catching this in the unhandled exception handler and the application does continue working afterwards:

private static void ApplicationThreadException(object sender, ThreadExceptionEventArgs e)    {       

if (e.Exception.Message == "NoDriver calling waveInPrepareHeader")            {               

//USB audio unplugged (typically the cause) - no other way to catch this exception in the volume level control due to limitation in NAudio           

}            else            { 

}

}

Coordinator
Mar 7, 2012 at 12:44 PM

have checked in some code that will form part of the next version of NAudio. The PlaybackStopped and RecordingStopped events now contain an Exception property that you can examine to see why playback stopped