Dilip Apte

Dilip Apte

  • NA
  • 8
  • 24.3k

Playing MP3 / wav file in WPF

Jul 12 2010 1:34 AM

Hi,
I am trying to play a local MP3 / wav file in WPF form but unable to here sound. System is not giving any error but sound cannot be heard. I am able to play file form windows media player outside the application.
Here is the xaml code
<
MediaElement Canvas.Left="441" Canvas.Top="395" Height="18" Name="mysound" Width="24" MediaOpened="mysound_MediaOpened" Volume="1" LoadedBehavior="Manual" />
and cs code:
private
void button1_Click(object sender, RoutedEventArgs e)
{
mysound.Source =
new Uri("/sounds/jungle_drum.wav", UriKind.Relative);
mysound.Play();

}
I tried both UriKind.Relative and Absolute but it didn't work. Sounds folder is in the root of project folder.
Can anyone help me debugging?
Regards.
Dilip

Answers (6)