I'm currently using the SoundPlayer of System.Media
in my Windows Forms application, but thereby I can't play multiple sounds simultaneously. I know, there are already answered questions for this topic, but if I'm trying to use the Windows Media Player:
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")
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?
CodePudding user response:
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
CodePudding user response:
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.
Second, choose Windows Media Player you can search in the upper right corner.
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();
}
}
}