Open osbeorn opened 7 years ago
What operating system are you running on?
Does it happen immediately, or after the application has been running for some time?
Win10 x64. It happens after sometime. And it seems quite random.
The underlying COM object may get destroyed.
Taking a quick look at the session code, there may be some enhancements in that space regarding object lifecycle.
One more thing ... My application is basically a stopwatch, which plays a command on start and plays another random audio track on end. It seems that just one specific audio track triggers this error.
The audio track is a 10s long .wav file of some song.
The code used to play the track:
using (var player = new SoundPlayer((UnmanagedMemoryStream) sound)) { player.Play(); }
Are you able to create a gist or attach a piece of self contained code that can be used to reproduce it? If you can, it should be fairly easy to track down and fix.
Here you go: fireDeptStopwatchGist.zip
Run the project, press Start, wait for the counter to start counting and then press Stop. You should get the mentioned exception.
It seems that the main problem is this block of code:
using (var player = new SoundPlayer((UnmanagedMemoryStream) sound)) { player.Play(); }
If I remove the using block and normally create a new SoundPlayer instance, the application stops crashing. It seems the SoundPlayer instance created inside the using block is getting disposed before it finishes playing the sound.
But if I remove your library, the SoundPlayer works fine even when using it with the using block.
I had a look at this in the weekend, and it's definitely in the Session Initialization code.
I should be able to track it down, and make a fix for it. I'll tag the commit in here, once it's done.
Cheers.
Hello,
I randomly encounter the following error in my program when using this library:
The following line of code is enough to trigger the exception:
var sessions = audioController.DefaultPlaybackDevice.GetCapability<IAudioSessionController>();
Any clue what might be wrong?