我正在开发一个简单的应用程序来使用 PlaySound 播放 WAV 文件,代码如下:
#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);
}
但是当我执行它并选择一个 WAV 文件(有 2 分钟的声音)时,我什么也没听到。
我需要做什么?谢谢。