C# 从您的资源中一次播放多个音频文件?

标签 c# resources wav audio

我希望能够在播放音乐时按下按钮来播放按下按钮的声音。 SoundPlayer 没有帮助,因为它停止了音乐播放声音。 我已将声音添加到我的资源 (WindowsFormsApplication2.Resources.Properties.button),我不想输入文件位置。

最佳答案

来自 MerickOWA 的回答

You CANNOT play two sounds at once using SoundPlayer.

SoundPlayer is using the native WINAPI PlaySound function to accomplish the task which has no support for playing simultaneous sounds. Creating multiple instances of SoundPlayer won't help.

There are many options most of which involve implementing a lot of the low level API to window's native audio library or DirectSound (note neither are C# and require alot of interop code)

The simplest option would be to depend on windows media player to play the audio for you.

Add a reference to "C:\Windows\System32\wmp.dll"

then use

var player = new WMPLib.WindowsMediaPlayer();
player.URL = @"..\..\bin\debug\tribal dance.wav";

Note: play starts immediately after setting the URL property

The down side of this approach is your reliance on media player for your application to work properly. On the upside, you can use any file format media player supports.

关于C# 从您的资源中一次播放多个音频文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20086058/

相关文章:

python - 生成的正弦波听起来嗡嗡作响或 'square' 而不是正弦波

audio - 播放时WAV文件错误-重建时需要帮助

c# - .net Autowiring 解决加载重复装配

grails - 在 Grails 1.4 中,静态不返回任何 css 或 js 资源

.net - 如何在资源字典中正确定义颜色?

将任务分配给资源的算法

python - 在python中拆分wav文件

c# - ASP.net 中的 Entity Framework

c# - EF 4.3 CodeFirst MVC3 WebApp 和控制台使用相同的模型,但不知何故它们 'see' 是导致模型支持错误的不同模型

C# - 程序显示该月中所有同一天的日期,用户输入