To make it clear: i tried to find a solution by looking at other posts in this forum but without effect (maybe because of my still weak knowledge of programming in c#).
I am currently developing an RTS game. Like games do - they make sounds.
Currently i can play sounds simultaneously when a button is pressed using this code:
using System.Runtime.InteropServices;
int a = 1;
[DllImport("winmm.dll")]
static extern Int32 mciSendString(string command, StringBuilder buffer, int bufferSize, IntPtr hwndCallback);
private void button4_Click(object sender, EventArgs e)
{
mciSendString(@"open 2.wav type waveaudio alias sound2" + a, null, 0, IntPtr.Zero);
mciSendString(@"play sound2" + a, null, 0, IntPtr.Zero);
// mciSendString("close sound2" + a, null, 0, IntPtr.Zero);
a+=1;
}
It works, but only when each time an alias is different than previous (that's why i use incrementing digit in the name). But.. If the sounds during game playing will be played, let's say 10 000 times.. would it "eat" much of memory?
Should code be changed? Is there a "better" option to do that? I was looking for code of condition which closes it after playing is completed but.. I want also to let a sound be played 0.2s after sound (which is 2-10s long depending of sound used) - so there would be an echo. I saw some codes with Dispose word, but i do not know how to use it.
When i was writing this post i thought i figured out a possible solution:
mciSendString("open 1.wav type waveaudio alias sound1" + a, null, 0, IntPtr.Zero);
mciSendString("play sound1" +a, null, 0, IntPtr.Zero);
mciSendString("close sound1" +(a-1), null, 0, IntPtr.Zero);
a+=1;
but first played sound stops before second time is played.
Is there a more "professional" solution to do that? Or this is just fine?
I hope i described my problem clearly.