Win32播放声音 [英] Win32 Play sound

查看:140
本文介绍了Win32播放声音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


bool Win64Sound :: PlayIt(){

    // return !! PlaySoundW(WideStringSoundFileName.c_str(),NULL,SND_FILENAME);

    return !! sndPlaySound(StringSoundFileName).c_str(),SND_ASYNC);

}

bool Win64Sound::PlayIt() {
    //return !!PlaySoundW(WideStringSoundFileName.c_str(), NULL, SND_FILENAME );
    return !!sndPlaySound(StringSoundFileName).c_str(),SND_ASYNC);
}

我使用 PlaySoundW测试了这个成员函数( )并没有问题,但
sndPlaySound()不会产生任何声音。我正在链接
-lwinmm -mwindows

I have tested this member function using PlaySoundW() and had no problems, but sndPlaySound() does not produce any sound. I am linking against -lwinmm -mwindows

我使用的是Win 8.1机器。

I am using a Win 8.1 machine.

这里的任何人都知道可能出现什么问题?

Anyone here knows what could be the problem?

推荐答案

嗯,除了sndPlaySound行中明显的编译器错误,你有sndPlaySound的SND_ASYNC但不是PlaySound,是否将SND_ASYNC添加到PlaySound,或者从sndPlaySound中删除它会有什么区别?

Well, besides the obvious compiler error in the sndPlaySound line, you have SND_ASYNC for sndPlaySound but not for PlaySound, does adding SND_ASYNC to PlaySound, or removing it from sndPlaySound make any difference?

否则,唯一要注意的是确保StringSoundFileName具有正确的路径,因为它是PlaySound使用的WideStringSoundFileName的不同变量。

Otherwise, the only other things to look at is to make sure that the StringSoundFileName has the correct path, since it is a different variable to WideStringSoundFileName that PlaySound uses.

无论如何,仅为了向后兼容性而维护sndPlaySound。如果可以的话,我建议你把所有内容改为PlaySound。更重要的是,这两个基本上已被WASAPI取代。

Anyway, sndPlaySound is only being maintained for backwards compatibility. If you can, I would suggest you change everything over to PlaySound anyway. What's more, both of these have basically been superseded by WASAPI.


这篇关于Win32播放声音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆