When playbackdevice disapears from windows playback devices (when user unplugs device from usb or audio jack port or disable it) while playling file, an COMException occrus in DirectSoundOut.StopPlayback() method on line 475: secondaryBuffer.Stop();
I don't know if it is possible to handle the exception from wpf application since it is in another thread.
I attached working sample project. just click the play button and unplug the device. if there's more than one playback device, then disable them. Exception occurs only when last device is disabled/uplugged.
You have a try..catch..finally bock in PlaybackThreadFunc, but when an exception is caught, then you call the com methods in finally block without try catch. You should at least use try..catch(ComException).
System.Runtime.InteropServices.COMException was unhandled
Message=Exception from HRESULT: 0x88780096
Source=NAudio
ErrorCode=-2005401450
StackTrace:
at NAudio.Wave.DirectSoundOut.IDirectSoundBuffer.Stop()
at NAudio.Wave.DirectSoundOut.StopPlayback() in C:\Users\Admin\Desktop\NAudio\naudio_db92aece4b2f\NAudio\Wave\WaveOutputs\DirectSoundOut.cs:line 475
at NAudio.Wave.DirectSoundOut.PlaybackThreadFunc() in C:\Users\Admin\Desktop\NAudio\naudio_db92aece4b2f\NAudio\Wave\WaveOutputs\DirectSoundOut.cs:line 442
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
Comments: I recently got this exception running [2339a04e76cc](https://naudio.codeplex.com/SourceControl/changeset/2339a04e76cc) from March 28, 2013. It was after recently switching from WaveOut to DirectSoundOut (which works a lot faster with super low latency!!!) Exception Type: System.Runtime.InteropServices.COMExceptionException Message: Exception from HRESULT: 0x88780096 Stack Trace: at NAudio.Wave.DirectSoundOut.IDirectSoundBuffer.Stop() at NAudio.Wave.DirectSoundOut.StopPlayback() in C:\Users\Brandon\Projects\RemoteHams.com\NAudio\Wave\WaveOutputs\DirectSoundOut.cs:line 485 at NAudio.Wave.DirectSoundOut.PlaybackThreadFunc() in C:\Users\Brandon\Projects\RemoteHams.com\NAudio\Wave\WaveOutputs\DirectSoundOut.cs:line 446 at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart() I see that line 446, as in the crash report, follows the report above. StopPlayback is called in a finally statement without exception handling. Making it difficult for the calling application to capture the exception. I will try the suggested fix and see if that helps prevent any further exceptions and report back here.
I don't know if it is possible to handle the exception from wpf application since it is in another thread.
I attached working sample project. just click the play button and unplug the device. if there's more than one playback device, then disable them. Exception occurs only when last device is disabled/uplugged.
You have a try..catch..finally bock in PlaybackThreadFunc, but when an exception is caught, then you call the com methods in finally block without try catch. You should at least use try..catch(ComException).
System.Runtime.InteropServices.COMException was unhandled
Message=Exception from HRESULT: 0x88780096
Source=NAudio
ErrorCode=-2005401450
StackTrace:
at NAudio.Wave.DirectSoundOut.IDirectSoundBuffer.Stop()
at NAudio.Wave.DirectSoundOut.StopPlayback() in C:\Users\Admin\Desktop\NAudio\naudio_db92aece4b2f\NAudio\Wave\WaveOutputs\DirectSoundOut.cs:line 475
at NAudio.Wave.DirectSoundOut.PlaybackThreadFunc() in C:\Users\Admin\Desktop\NAudio\naudio_db92aece4b2f\NAudio\Wave\WaveOutputs\DirectSoundOut.cs:line 442
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
Comments: I recently got this exception running [2339a04e76cc](https://naudio.codeplex.com/SourceControl/changeset/2339a04e76cc) from March 28, 2013. It was after recently switching from WaveOut to DirectSoundOut (which works a lot faster with super low latency!!!) Exception Type: System.Runtime.InteropServices.COMExceptionException Message: Exception from HRESULT: 0x88780096 Stack Trace: at NAudio.Wave.DirectSoundOut.IDirectSoundBuffer.Stop() at NAudio.Wave.DirectSoundOut.StopPlayback() in C:\Users\Brandon\Projects\RemoteHams.com\NAudio\Wave\WaveOutputs\DirectSoundOut.cs:line 485 at NAudio.Wave.DirectSoundOut.PlaybackThreadFunc() in C:\Users\Brandon\Projects\RemoteHams.com\NAudio\Wave\WaveOutputs\DirectSoundOut.cs:line 446 at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart() I see that line 446, as in the crash report, follows the report above. StopPlayback is called in a finally statement without exception handling. Making it difficult for the calling application to capture the exception. I will try the suggested fix and see if that helps prevent any further exceptions and report back here.