[英]How can I play multiple sounds in C# simultaneously?
I'm currently using the SoundPlayer of System.Media
in my Windows Forms application, but thereby I can't play multiple sounds simultaneously.我目前在我的 Windows Forms 应用程序中使用
System.Media
的 SoundPlayer,但因此我无法同时播放多个声音。 I know, there are already answered questions for this topic, but if I'm trying to use the Windows Media Player:我知道,这个主题已经回答了问题,但是如果我尝试使用 Windows 媒体播放器:
using System.Windows.Media
I get an error:我收到一个错误:
The "System.Windows.Media" is not found ("the type or namespacename "Media" is not available in the namespace Windows.Media")
未找到“System.Windows.Media”(“类型或命名空间名称“Media”在命名空间 Windows.Media 中不可用”)
I think there is missing an assembly, but I don´t know how to add it.我认为缺少一个程序集,但我不知道如何添加它。 Isn't there an easy way to play multiple sounds at the same time?
有没有一种简单的方法可以同时播放多个声音?
Where can I find the solution explorer?
我在哪里可以找到解决方案资源管理器?
Use the Quick search in the menu bar:使用菜单栏中的快速搜索:
It will tell you where to find the entry in the menu or which shortcut to use.它会告诉您在哪里可以找到菜单中的条目或使用哪个快捷方式。
How do I add a reference?
如何添加参考?
Use the quick search in the menu bar:使用菜单栏中的快速搜索:
It will tell you where to find the action in the menu.它会告诉您在菜单中的何处可以找到该操作。
"System.Windows.Media" is not found
未找到“System.Windows.Media”
Can't find System.Windows.Media namespace : it's part of PresentationCore.dll
. 找不到 System.Windows.Media 命名空间:它是
PresentationCore.dll
的一部分。 Use the search box to find it quickly:使用搜索框快速找到它:
new try of adding assemblies in the reference manager Here you can see where I typed it in在引用管理器中添加程序集的新尝试在这里你可以看到我在哪里输入
So am I doing anything wrong right there?那么我在那里做错了什么吗?
If you want to play multiple sounds in C# simultaneously, you can refer to the following steps: First, right click on References in Solution Explorer an choose Add Reference.如果要同时播放 C# 中的多个声音,可以参考以下步骤:首先,在解决方案资源管理器中右键单击参考,然后选择添加参考。
Second, choose Windows Media Player you can search in the upper right corner.二、选择Windows媒体播放器可以在右上角搜索。
Finally, you can use the following code:最后,您可以使用以下代码:
using System;
using WMPLib;
namespace ConsoleApp3
{
class Program
{
static void Main(string[] args)
{
var sound1 = new WindowsMediaPlayer();
sound1.URL = @"path of sound1";
var sound2 = new WindowsMediaPlayer();
sound2.URL = @"path of sound2";
Console.ReadLine();
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.