play sound

  • Thread starter Thread starter yuen
  • Start date Start date
Here's an example... you play the sounds by importing the PlaySound method
from the winmm.dll...

public class Sound
{
public enum Sounds
{
Chord,
Ding
}
[DllImport("winmm.dll", ExactSpelling=true, EntryPoint="PlaySound",
CharSet=CharSet.Ansi)]
public static extern int PlaySound(String pszSound, int hmod, PlaySoundFlag
fdwSound);
public enum PlaySoundFlag
{
// Play synchronously (default)
Synchronously = 0x0000,
// Play asynchronously
Asynchronously = 0x0001,

// Silence (!default) if sound not found
NoDefault = 0x0002,
// pszSound points to a memory file
Memory = 0x0004,
// Loop the sound until next sndPlaySound
Loop = 0x0008,
// Don't stop any currently playing sound
NoStop = 0x0010,
// Don't wait if the driver is busy
NoWait = 0x00002000,
// Name is a registry alias
Alias = 0x00010000,
// Alias is a predefined ID
AliasId = 0x00110000,
// Name is file name
Filename = 0x00020000,
// name is resource name or atom
Resource = 0x00040004,
// Purge non-static events for task
Purge = 0x0040,

// Look for application specific association
Application = 0x0080
}
public static void Play(string fileName)
{
try
{
PlaySound(fileName,0,0);
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
}
}
 
Back
Top