Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.
How to embed and play a .wav file in Windows Phone 7 app
This article describes how to embed a WAV file into the WP7 app and play it later.
- First let us create a Windows Phone Application. To create it, open Visual Studio and select Windows Phone Application from the installed templates.
- Select Windows Phone 7.1 as the Target Version.
- Right-click on the “References” in the project and click “Add Reference…”. Find the “Microsoft.Xna.Framework” reference and add it to your project.
Embedding WAV File
- Let's Add WAV File.To do this right-click on the project and add new folder. Give desired name to this folder. Here, I am naming it as Sound.
- Right-click on the Sound folder and add existing items. Add WAV file to this folder.
- After adding WAV file select the file and right-click and open Properties and change the “Build Action” to “Resource”
- Add the following namespace to the MainPage.xaml.cs file
- Code to play the .wav file
void Play_wavFile(object sender, EventArgs e)
StreamResourceInfo _stream = Application.GetResourceStream(new Uri("/AgeCalculator;component/Sound/BirthdayTune.wav", UriKind.Relative));
SoundEffect _soundeffect = SoundEffect.FromStream(_stream.Stream);
SoundEffectInstance soundInstance = _soundeffect.CreateInstance();
To play the wav file on a button press
Private void button1_Click(object sender, RoutedEventArgs e)
- Now build the project and run it using F5.