Friday, June 1, 2012

Windows 8 Metro : Playing Sound Files

While playing sound files using XAML in VS 11, you have to follow these steps:
1) VS 11 doesn't support Build Action as "Resource", so you have to add a sound file and set its Build as "Content" and set its "Copy to Output Directory" as "Copy if Newer"





















2) Add a MediaPlayer in your XAML , (it doesn't have sound player).
<MediaPlayer Height="100" x:Name="MediaPlayer" Canvas.Left="10" Canvas.Top="99" Width="100"/>

3) Now Because of some bug in Media Player , you have to set "Source" path in your code as shown below.

MediaPlayer.Source = new Uri(Board.Current.SoundPlayer.BaseUri, "/Sounds/Hit02.wav");



4) Now Call Play method on MediaPlayer to start playing your sound file.

MediaPlayer.Play();

No comments:

Post a Comment