0

Right now this is the code I have. Apparently SoundPlayer doesnt exist in the namespace System.media

System.Media.SoundPlayer player = new System.Media.SoundPlayer(@"c:\waterfall.wav");
   player.Play();

What else can i use? I mean theres tons of ways to do it in a window application but...

  • 1
    Maybe this helps? https://stackoverflow.com/a/22030431/10708630 – turanszkik Sep 09 '21 at 07:45
  • It should work just like that. Do you, by any chance, have a namespace System.Media that does not define SoundPlayer? Which version of .NET are you targeting? – juanferrer Sep 09 '21 at 08:13
  • Do pay attention to the project template you selected to get started. For .NETCore and .NET 5.0 (aka ".NET") you need https://www.nuget.org/packages/System.Windows.Extensions/ – Hans Passant Sep 09 '21 at 11:45

1 Answers1

0

Try setting the SoundLocation property before playing and it should work

var soundPlayer = new SoundPlayer();
soundPlayer.SoundLocation = Environment.CurrentDirectory + "/waterfall.wav";
Ran Turner
  • 14,906
  • 5
  • 47
  • 53