如何在线程中播放声音? [英] how to PlaySound in threads?

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

问题描述

当我用 Playsound 播放音乐时.PlaySound("XX.wav",NULL,SND_ASYNC|SND_LOOP) 如果我播放另一个 .wav 文件,它会停止这个文件(XX.wav).

When I play music with Playsound for exmp. PlaySound("XX.wav",NULL,SND_ASYNC|SND_LOOP) if I play then another .wav file it stops this file(XX.wav).

我认为使用线程可以避免这个问题.但是如何在 WinApi 中实现?Threadfunc 会是什么样子?

I think this problem can be avoided with threads. But how to make it in WinApi?How Threadfunc will look like?

当我想在按 SPACE 时停止音乐但又不想在调用另一个 PlaySound 时停止它时如何使用它.

And How to use it when I want to stop music when I press SPACE but I do not want to stop it when I call another PlaySound.

推荐答案

PlaySound() 一次只能播放一种声音.线程不会改变这一点.要同时播放多个声音,您需要:

PlaySound() can only play one sound at a time. Threading will not change that. To play multiple sounds at the same time, you need to either:

1) 自己将音频帧混合在一起,然后将音频缓冲区推送到 waveOutWrite().

1) mix the audio frames together yourself and then push your audio buffers to waveOutWrite().

2) 使用 DirectSound API.它允许您将多种声音混合在一起播放.

2) use the playback capabilities of the DirectSound API. It allows you to mix multiple sounds together during playback.

我建议#2.

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

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