使用 PlaySound 时听不到任何声音

发布于 2024-08-11 01:18:19 字数 883 浏览 4 评论 0原文

我正在开发一个简单的应用程序,使用 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 分钟的声音)时,我没有听到任何声音。

我需要做什么?谢谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

空城仅有旧梦在 2024-08-18 01:18:19

正如 curtisk 指出的那样,您应该尝试使用 SND_FILENAME 让 API 知道您正在传递文件名。此外,请注意 PlaySound 方法有一个返回值,值得检查您返回的内容 - 根据 MSDN 文档,成功则返回 0,失败则返回非零。

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.

始终不够 2024-08-18 01:18:19

您应该使用 SND_FILENAME 标志而不是 SND_SYNC,因为您正在指定一个文件,请尝试一下,看看是否可以你会有更好的结果...

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...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文