Reputation: 2883
I would like to ask you about why the sound cannot be played if the path is not same as: C:/Windows/Media/NameOfTheFile.wav
.
I have this function:
public class SystemManager
{
static SoundPlayer _soundPlayer = new SoundPlayer();
public static void SoundEffect(string _soundLocation)
{
_soundPlayer.SoundLocation = _soundLocation;
_soundPlayer.Play();
}
}
and call it like this:
void Login_Load(object sender, EventArgs e)
{
SystemManager.SoundEffect("C:/Windows/Media/Savanna/Windows Exclamation.wav");
}
The above code did not work, the sound will not play.
But when I tried the below code, it does play.
void Login_Load(object sender, EventArgs e)
{
SystemManager.SoundEffect("C:/Windows/Media/Windows Exclamation.wav");
}
Here is the image:
Upvotes: 1
Views: 473
Reputation: 6813
The problem is not the location - the problem is the sound file you are trying to play. When I run the same code, I get the following exception:
Sound API only supports playing PCM wave files.
The sounds in C:/Windows/Media
are PCM, but the sounds in the subfolders are not. You'll either need to find a way to convert them to PCM or find a different method of playing them.
Upvotes: 2