-1

I want to play multiple sounds simultaneously in my Winforms project, but I am not able to add the Windows Media Player as an assembly to my project, because .NET Framework is missing in my Core 6 Project.

The following code should be ported to .NET Core 6:

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();
        }
    }
}
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
heermaas
  • 5
  • 5
  • 1
    https://stackoverflow.com/questions/70088775/windows-media-player-in-net-5-0/70091520 – pm100 Jan 08 '22 at 18:39
  • @pm100 Thanks for your help, but I have allready seen this question. I just do not understand how the first step of the described solution works. Which file should be the project file and where exactly can i find it? And what of the shown "text/code" should be typed in then? – heermaas Jan 08 '22 at 18:44
  • .csproj is the project file – pm100 Jan 08 '22 at 19:15
  • 1
    Please stop tagging your .NET questions [assembly]. This isn't assembly-language. There's no `add eax, [rdi]` or other machine instructions for x86-64 or any other ISA. You found the [.net-assembly] tag, probably from my edit to [your last question](https://stackoverflow.com/questions/70633987/how-to-transform-a-winforms-app-into-winforms-app-net-framework-easily), but I guess didn't read the tooltip for the [assembly] tag you used again here. – Peter Cordes Jan 08 '22 at 20:09

1 Answers1

0

If you want to play multiple sounds simultaneously in .Net 6 Winforms project, you can refer to the following steps:

First doubule-click on the project and open the project file WinFormsApp1.csproj. enter image description here enter image description here

Second add the following code in the file:

   <UseWindowsForms>true</UseWindowsForms>
   <UseWPF>true</UseWPF>

Then we can use the code in Form1.cs:

using System.Windows.Media;

namespace WinFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            var sound1 = new MediaPlayer();
            sound1.Open(new Uri(@"path of sound1"));
            sound1.Play();
            var sound2 = new MediaPlayer();
            sound2.Open(new Uri(@"path of sound2"));
            sound2.Play();
        }
    }
}

Finally we can play multiple sounds simultaneously.

Jingmiao Xu-MSFT
  • 2,076
  • 1
  • 3
  • 10