Playing Wav with Directsound

3.2k views Asked by At

I need to play multiple wave files which start at different times (not all together). I was trying to play the files using Directsound but a problem arised. I have the following code:

var dev = new Device();      //This line creates the problem
dev.SetCooperativeLevel(this, CooperativeLevel.Normal);
MemoryStream ms = new MemoryStream(Sample1);
soundBuffer = new Microsoft.DirectX.DirectSound.Buffer(ms, dev);
SecondaryBuffer sound = new SecondaryBuffer(ms,dev);
sound.Play();

The problem is when I type in the first line (var dev = new Device();), and compile the program an error occurs (ConsoleApplication1 encountered a problem and needs to close). This happens even when I remove all the code except the first line. The console error is as follows: "Mixed mode assembly is built against version v1.1.4322 of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information".

If this problem is not fixable, is there another way to play multiple sounds. The sound has to have minimum latency and must play instantly without any delays.

1

There are 1 answers

1
GWLlosa On

You need to edit your application configuration to include:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0"/>
  </startup>
</configuration>

Which should allow you to use older .NET dlls.