0
using System;
using System.Collections.Generic;
using System.Text;
using Sys = Cosmos.System;
using System.Threading;
using System.Media.SoundPlayer;

Since cosmos uses c#, I am trying to use System.Media.SoundPlayer to play a sound file, but visual studio shows a red squiggle under "Media", saying "The type or namespace doesn't exist in the namespace 'System'(are you missing an assembly reference)". How should I resolve this?

1 Answers1

1

If I remember correctly, SoundPlayer is not a namespace, its the class name. So you can just import the media namespace and use the SoundPlayer like below.

using System.Media;

and in code, use like this:

SoundPlayer player = new SoundPlayer (@"###.mp3");
player.Play();

Hope this helps.

HRM
  • 2,097
  • 6
  • 23
  • 37
  • I tried the method you suggested but visual studio is still showing a red squiggle under "Media" – Ayanabha Jana May 12 '20 at 12:28
  • Oops, I think its a .Net core project and may not have support. Could you please check whether this SO question is helpful - https://stackoverflow.com/questions/42845506/how-to-play-a-sound-in-netcore – HRM May 13 '20 at 05:09