Hi,
I am working on a c# application that is supposed to play several soundfiles over different output devices.
After much searching I stumbled over the winmm.dll-API. However, I have trouble to propperly set the output-device befor I play a sound.
Here is my code so far:
MCI_OPEN_PARMS open = new MCI_OPEN_PARMS();
open.wDeviceID = 0;
open.lpstrDeviceType = Marshal.StringToHGlobalAnsi("waveaudio");
open.lpstrElementName = Marshal.StringToHGlobalAnsi(@"test.wav");
IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(MCI_OPEN_PARMS)));
Marshal.StructureToPtr(open, ptr, false);
uint err = mciSendCommand(0,
MCI_OPEN,
MCI_WAIT | MCI_OPEN_TYPE | MCI_OPEN_ELEMENT,
ptr);
if (0 != err) ThrowException(err);
open = (MCI_OPEN_PARMS)Marshal.PtrToStructure(ptr, typeof(MCI_OPEN_PARMS));
uint devID = open.wDeviceID;
MCI_PLAY_PARMS play = new MCI_PLAY_PARMS();
play.dwCallback = IntPtr.Zero;
play.dwFrom = 0;
play.dwTo = 0;
IntPtr ptr2 = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(MCI_PLAY_PARMS)));
Marshal.StructureToPtr(play, ptr2, false);
err = mciSendCommand(devID,
MCI_PLAY,
MCI_NOTIFY, ptr2);
if (0 != err) ThrowException(err);
All the neccesary constants and structures are in the class-definition.
The second line (open.wDeviceID = 0;) should be the one to set the output-device, but no matter what I enter, the sound comes always out of the default-output.
I also used the winmm.dl functions waveOutGetNumDevs and waveOutGetDevCaps to list the avaliable output devices. It schows me, that I have speakers and an external USB-Soundcard, like expected.
Help would be much apreciated.
Best Regards, Marc