Long delay playing sound for Win API

  • Thread starter Thread starter Dennis C. Drumm
  • Start date Start date
D

Dennis C. Drumm

Using the Win API to play a sound with the code below in my Windows Form
application. I get a huge delay (seems like application is hanging) just
prior to the sound being played each time. Is this something to do with
unmanaged code? Is there any way to fix the delay and speed the process up?

Thanks,

Dennis

using System.Runtime.InteropServices;

[DllImport("winmm.dll")]

public static extern int sndPlaySound(string lpszSoundName, int uFlags);

sndPlaySound("Windows XP Exclamation.wav", 0x001);
 
Dennis:

I've used this a fair amount on both the Desktop and Pocket PC and haven't
noticed any performance degradation.

Mine implementation is slightly different, but I don't think that's the
cause---I had just read that you should use constants instead...

Define two constants...
public const int SND_FILENAME = 0x00020000;
public const int SND_ASYNC = 0x0001;

Define PlaySOund ass

public static extern bool PlaySound(string pszSound, int hmod, int
fdwSound);

then the call would be PlaySound("Windows XP Exclamation.wav",
SND_FILENAME|SND_ASYNC);

See if this doesn't make a difference.

BTW, I got the code originally from John Paul Mueller's .NET Framework
Solutions....I don't want to take credit for his stuff. He does mention
that you should use the COnstants, so maybe that's a possible issue.

Not sure...but maybe this helps.

Cheers,

BIll
 
Actually, I was using the public const int's as well, I just was trying to
save space on my post. I tried it in a clean test app and didn't experience
the dalay, so its something to do with my windows form app. I should have
tried that before.

Dennis


William Ryan said:
Dennis:

I've used this a fair amount on both the Desktop and Pocket PC and haven't
noticed any performance degradation.

Mine implementation is slightly different, but I don't think that's the
cause---I had just read that you should use constants instead...

Define two constants...
public const int SND_FILENAME = 0x00020000;
public const int SND_ASYNC = 0x0001;

Define PlaySOund ass

public static extern bool PlaySound(string pszSound, int hmod, int
fdwSound);

then the call would be PlaySound("Windows XP Exclamation.wav",
SND_FILENAME|SND_ASYNC);

See if this doesn't make a difference.

BTW, I got the code originally from John Paul Mueller's .NET Framework
Solutions....I don't want to take credit for his stuff. He does mention
that you should use the COnstants, so maybe that's a possible issue.

Not sure...but maybe this helps.

Cheers,

BIll
Dennis C. Drumm said:
Using the Win API to play a sound with the code below in my Windows Form
application. I get a huge delay (seems like application is hanging) just
prior to the sound being played each time. Is this something to do with
unmanaged code? Is there any way to fix the delay and speed the process up?

Thanks,

Dennis

using System.Runtime.InteropServices;

[DllImport("winmm.dll")]

public static extern int sndPlaySound(string lpszSoundName, int uFlags);

sndPlaySound("Windows XP Exclamation.wav", 0x001);
 
Back
Top