gpt4 book ai didi

c++ - 使 PlaySound 成为非阻塞的

转载 作者:可可西里 更新时间:2023-11-01 09:44:30 26 4
gpt4 key购买 nike

我一直在测试声音,我注意到 PlaySound 是阻塞的,即它会等到声音播放完毕才返回。

#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;
}

此代码播放声音,但它会等待输出“这个声音很酷”,直到声音播放完毕。我怎样才能让它不那样做?

最佳答案

异步播放声音:

PlaySound(L"E:\\Downloads\\eb_sfx_archive\\brainshock.wav", NULL, SND_ASYNC);

来自MSDN文档:

The sound is played asynchronously and PlaySound returns immediately after beginning the sound. To terminate an asynchronously played waveform sound, call PlaySound with pszSound set to NULL.

关于c++ - 使 PlaySound 成为非阻塞的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41421313/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com