include
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Media;
Step 2:
declaration
private SoundEffect lionSound;
Step 3:
include the source code in Constructor MainPage()
// Prime the pump or we'll get an exception.
FrameworkDispatcher.Update();
// Create and load SoundEffect objects.
LoadSound("Sounds/lionSound.wav", out lionSound);
Step 4:
/// Loads a wav file into an XNA Framework SoundEffect.
/// <param name="SoundFilePath">Relative path to the wav file.</param>
/// <param name="Sound">The SoundEffect to load the audio into.</param>
private void LoadSound(String SoundFilePath, out SoundEffect Sound)
{
// For error checking, assume we'll fail to load the file.
Sound = null;
try
{
//test
Uri uri = new Uri(SoundFilePath, UriKind.Relative);
// Holds informations about a file stream.
StreamResourceInfo SoundFileInfo = App.GetResourceStream(uri);
// Create the SoundEffect from the Stream
Sound = SoundEffect.FromStream(SoundFileInfo.Stream);
}
catch (NullReferenceException)
{
// Display an error message
MessageBox.Show("Couldn't load sound " + SoundFilePath);
}
}
Step 5:
call the function
private void button1_Click(object sender, RoutedEventArgs e)
{
try
{
lionSound.Play();
}
catch (NullReferenceException)
{
MessageBox.Show("Can't play, lionSound is null.");
}
}
Here was the source code