Play an audio file in Windows 7 Phone

Aqueel picture Aqueel · Oct 26, 2010 · Viewed 19k times · Source

I am working on Windows 7 based application development in Silverlight. I have not been able to find a way to play a an audio file in windows 7 phone programmatically. I have been googling it since past few days but i could not get any solution of that. There is a class SoundPlayer in C# but i guess its not available in Windows 7 Phone. Can anyone please help?

Answer

Olivier Payen picture Olivier Payen · Oct 26, 2010

You can place a MediaElement in your XAML view:

<MediaElement 
    x:Name="sound" 
    Source="sound.wma" 
    AutoPlay="False" />

then in the code-behind:

sound.Play();

Supported formats are MP3 and WMA.