0

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?

assembly manager

Thomas Weller
  • 55,411
  • 20
  • 125
  • 222
heermaas
  • 5
  • 5
  • Not tested but maybe like this https://stackoverflow.com/questions/1285294/play-multiple-sounds-using-soundplayer – Bas H Dec 12 '21 at 10:12
  • Thats exactly what I meaned... They are using System.Windows.Media, what isn´t working for me... How can I get that to work? – heermaas Dec 12 '21 at 10:19
  • Where can I find the solution explorer? – heermaas Dec 12 '21 at 10:22
  • Question: What target framework are you using? .NET 5.0 (or later) or .NET Framework? – PMF Dec 12 '21 at 14:39
  • @PMF I think it is "NET Core 3.1", but I am not sure about it and I dont know where I can see it again... – heermaas Dec 12 '21 at 18:04
  • @heermaas You see the target framework in the property pages of the project. Right click the project->Properties->Application. There's an entry "Target framework". – PMF Dec 12 '21 at 18:29

2 Answers2

2

Where can I find the solution explorer?

Use the Quick search in the menu bar:

Using quick search

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:

Using quick search again

It will tell you where to find the action in the menu.

"System.Windows.Media" is not found

Can't find System.Windows.Media namespace: it's part of PresentationCore.dll. Use the search box to find it quickly:

PresentationCore

Thomas Weller
  • 55,411
  • 20
  • 125
  • 222
  • Thank your really much for your answer, but if I´m writing "solution" or "refere" in the search bar, I can´t find anything like you do. Maybe I do have to change the language? But if I´m typing in the german translation of solution, there is no meaningfull result too. Do I use the wrong search bar? What am I doing wrong? – heermaas Dec 12 '21 at 11:08
  • @heermaas: The solution explorer is normally open, either on the right or the left side of the code. In German, it's called "Projektmappen-Explorer". It might be collapsed all the way at the border of the screen (in vertical tabs). If you really don't have it, you can open it using the topmost entry in the "Ansicht" menu. – PMF Dec 12 '21 at 14:36
  • I know, that I was wrong being at the COM tab of the assembly manager, but there is no assembly tab, as you can see on the screenshot of my assembly manager – heermaas Dec 12 '21 at 17:03
  • @heermaas: what type of project is it? Are you sure it's a WinForms project? The assemblies part is missing in a web project or a C++ project. Which VS version are you using? – Thomas Weller Dec 12 '21 at 17:11
  • Yes, I am using the whole features of winforms (like forms with buttons, labels and stuff like that), so it has to be a WinForm project, right? And I am using VS Community 2019, but where can I see the detailed version of it? Another question: How can I paste normal pictures (like you did) instead of links? – heermaas Dec 12 '21 at 17:18
  • @Thomas Weller Now I have updated my VS to the english version and thereby I found out the exact version of VS: 16.11.7 Thank you very much so far for the many tips. I am sorry for annoying that much, but as you can see, I am a bloody beginner and I am still not able to find an assembly tab :/ – heermaas Dec 12 '21 at 18:00
  • I also have VS 16.11.7 Community. It's really strange that "Assemblies" is missing. Can you create a new WinForms project from scratch and cross check there? – Thomas Weller Dec 12 '21 at 18:57
  • @ThomasWeller I got my mistake and I think it was just very stupid, because I created a Winforms App instead of Winforms App (.NET Framework), where I am able to add normal references, but now i do not know how to transfer my old project into a new one with ".NET Framework" – heermaas Dec 18 '21 at 12:03
0

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. enter image description here

Second, choose Windows Media Player you can search in the upper right corner. enter image description here

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();
        }
    }
}
Jingmiao Xu-MSFT
  • 2,076
  • 1
  • 3
  • 10