0

I'm developing a simple appplication to play WAV files using PlaySound, with this code:

#region DllImport
private enum Flags
{
    SND_SYNC = 0x0000,
    SND_ASYNC = 0x0001,
    SND_NODEFAULT = 0x0002,
    SND_MEMORY = 0x0004,
    SND_LOOP = 0x0008,
    SND_NOSTOP = 0x0010,
    SND_NOWAIT = 0x00002000,
    SND_ALIAS = 0x00010000,
    SND_ALIAS_ID = 0x00110000,
    SND_FILENAME = 0x00020000,
    SND_RESOURCE = 0x00040004
}
[DllImport("CoreDll.DLL", EntryPoint = "PlaySound", SetLastError = true)]
private extern static int MobilePlaySound(string szSound, IntPtr hMod, int flags);
public void PlaySound(string fileName)
{
    MobilePlaySound(fileName, IntPtr.Zero, (int)Flags.SND_SYNC);
}
#endregion

public Form1()
{
    InitializeComponent();
    openFileDialog1.ShowDialog();
    PlaySound(openFileDialog1.FileName);
}

But when I execute it and select a WAV file(with 2 mins of sound) I didn't heard anything.

What I need to do? Thanks.

Nathan Campos
  • 28,769
  • 59
  • 194
  • 300

2 Answers2

1

You should use SND_FILENAME flag instead of SND_SYNC, since you are specifying a file, try that out and see if you have better results...

curtisk
  • 19,950
  • 4
  • 55
  • 71
1

As curtisk points out, you should try using SND_FILENAME to let the API know you're passing in a filename. Additionally, note that the PlaySound method has a return value, it'd be worth checking what you're getting back - according to the MSDN documentation, it'll return 0 if successful and non-zero if not.

Chris
  • 4,661
  • 1
  • 23
  • 25