使PlaySound畅通无阻 [英] Make PlaySound non-blocking
本文介绍了使PlaySound畅通无阻的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直在测试声音,我注意到 PlaySound
正在阻止,即它等待直到声音播放完毕才返回.
I've been testing sounds and I noticed that PlaySound
is blocking, i.e. it waits until the sound has finished playing to return.
#include <iostream>
#include <Windows.h>
#include <mmsystem.h>
int main()
{
PlaySound("E:/Downloads/eb_sfx_archive/brainshock.wav", 0, SND_FILENAME);
std::cout << "this sound is cool";
Sleep (500);
std::cout << "\nmeh... not really";
return 0;
}
此代码播放声音,但是它等待输出此声音很酷",直到声音播放完毕为止.我该如何做呢?
This code plays the sound, but it waits to output "this sound is cool" until after the sound has finished playing. How can I make it not do that?
推荐答案
异步播放声音:
PlaySound(L"E:\\Downloads\\eb_sfx_archive\\brainshock.wav", NULL, SND_ASYNC);
从 MSDN 文档:
声音异步播放,开始发出声音后,
PlaySound
立即返回.要终止异步播放的波形声音,请在pszSound
设置为NULL
的情况下调用PlaySound
.
The sound is played asynchronously and
PlaySound
returns immediately after beginning the sound. To terminate an asynchronously played waveform sound, callPlaySound
withpszSound
set toNULL
.
这篇关于使PlaySound畅通无阻的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文