Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#从您的资源中一次播放多个音频文件?_C#_Resources_Wav_Audio - Fatal编程技术网

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

C#从您的资源中一次播放多个音频文件?,c#,resources,wav,audio,C#,Resources,Wav,Audio,我想能够按下一个按钮,播放一个按钮被按下的声音,而音乐已经播放。SoundPlayer没有帮助,因为它会停止音乐播放声音。 我已将声音添加到我的资源(WindowsFormsApplication2.Resources.Properties.button)中,我不想输入文件位置。从 不能使用SoundPlayer同时播放两种声音 SoundPlayer使用本机WINAPI PlaySound函数来完成不支持同时播放声音的任务。创建多个SoundPlayer实例没有帮助 有许多选项,其中大多数涉及

我想能够按下一个按钮,播放一个按钮被按下的声音,而音乐已经播放。SoundPlayer没有帮助,因为它会停止音乐播放声音。 我已将声音添加到我的资源(WindowsFormsApplication2.Resources.Properties.button)中,我不想输入文件位置。

不能使用SoundPlayer同时播放两种声音

SoundPlayer使用本机WINAPI PlaySound函数来完成不支持同时播放声音的任务。创建多个SoundPlayer实例没有帮助

有许多选项,其中大多数涉及到实现许多底层API到window的本机音频库或DirectSound(请注意,两者都不是C语言,并且需要大量互操作代码)

最简单的选择是依靠windows media player为您播放音频

添加对“C:\Windows\System32\wmp.dll”的引用

然后使用

var player = new WMPLib.WindowsMediaPlayer();
player.URL = @"..\..\bin\debug\tribal dance.wav";
注意:设置URL属性后立即开始播放

这种方法的缺点是依赖媒体播放器使应用程序正常工作。另一方面,您可以使用媒体播放器支持的任何文件格式