I have instantiated a System.Media.SoundPlayer
and I am (trying to) use it to play a .wav file. However, as you may have picked up from the title of this, it isn't working (no sound is being outputted). I am using C# and creating a Console application in Visual Studio 2017 Mac. Here is my code:
using System;
using System.Threading;
using System.IO; // Not needed yet
using System.Media;
namespace mathsTestConsoleC
{
public class OutputClass
{
public void PlayMusic()
{
SoundPlayer player = new SoundPlayer
{
SoundLocation = @"/Users/felix/Projects/mathsTestConsoleC/mathsTestConsoleC/backgroundMusic.wav"
};
player.Load();
player.Play();
}
}
}
(I realise that you don't necessarily need to use player.Load();
because the player.Play();
includes that.)
This doesn't work either:
public void PlayMusic()
{
SoundPlayer player = new SoundPlayer
{
SoundLocation = "/Users/felix/Projects/mathsTestConsoleC/mathsTestConsoleC/backgroundMusic.wav"
};
player.Load();
Thread.Sleep(500);
if (player.IsLoadCompleted == true)
{
player.Play();
}
else if (player.IsLoadCompleted == false)
{
Console.WriteLine("player.IsLoadCompleted == false");
}
else
{
Console.WriteLine("player.IsLoadCompleted == not set");
}
}
When I call PlayMusic()
, my application doesn't play the .wav file that I have given it.
I hope you can help!