Reputation: 2045
I know this has been asked before but am still not able to play a wav file in wpf.
This is the code I am using.
<MediaElement Name="mediaSound" LoadedBehavior="Manual" Source="Alarm10.wav"/>
and
try
{
mediaSound.Play();
}
catch (Exception a)
{
MessageBox.Show(a.Message);
}
No exception is thrown and the sound is not played.
Upvotes: 1
Views: 498
Reputation: 67918
Because there is nothing wrong with the markup, I'm left to only believe that the location of Alarm10.wav
is not in the bin\*
directory in which the application is executing out of.
Another thing that needs to be evaluated is the volume level of the MediaElement
, for example:
mediaSound.Volume = .75;
The OP confirmed it was the location of the WAV file that was the problem. When providing a path, it's relative to the WorkingDirectory
of the application. During debugging this is the directory in which it's executing out of (generally).
Upvotes: 1