×
Namespaces

Variants
Actions
(Difference between revisions)

How to embed and play a .wav file in Windows Phone 7 app

From Nokia Developer Wiki
Jump to: navigation, search
Vaishali Rawat (Talk | contribs)
(Vaishali Rawat -)
 
Vaishali Rawat (Talk | contribs)
(Vaishali Rawat -)
Line 1: Line 1:
 
[[Category:Draft]][[Category:Windows Phone]]
 
[[Category:Draft]][[Category:Windows Phone]]
{{Abstract|This article shows describes how to embed a WAV file into the WP7 app and play it later.}}
+
{{Abstract|This article describes how to embed a WAV file into the WP7 app and play it later.}}
  
 
{{ArticleMetaData <!-- v1.2 -->
 
{{ArticleMetaData <!-- v1.2 -->

Revision as of 16:23, 5 September 2012

This article describes how to embed a WAV file into the WP7 app and play it later.

WP Metro Icon File.png
WP Metro Icon Multimedia.png
SignpostIcon XAML 40.png
SignpostIcon WP7 70px.png
Article Metadata
Tested with
SDK: Windows Phone 7.1
Compatibility
Platform(s): Windows Phone 7.5
Windows Phone 7.5
Article
Created: Vaishali Rawat (05 Sep 2012)
Last edited: Vaishali Rawat (05 Sep 2012)

Getting Started

  • 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.
AddReference.png
XnaFramework.png

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.
AddWavFile.png
  • After adding WAV file select the file and right-click and open Properties and change the “Build Action” to “Resource”
BuildAction.png

Code Behind

  • Add the following namespace to the MainPage.xaml.cs file
 using System.Windows.Resources;
using Microsoft.Xna.Framework;
  • 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();
soundInstance.Play();
}

To play the wav file on a button press

Private void button1_Click(object sender, RoutedEventArgs e)
{
Play_wavFile();
}
  • Now build the project and run it using F5.
202 page views in the last 30 days.
×