Skip to content

Instantly share code, notes, and snippets.

@dgkanatsios
Created July 25, 2014 18:56
Show Gist options
  • Save dgkanatsios/bbb1bb8a6a52929af918 to your computer and use it in GitHub Desktop.
Save dgkanatsios/bbb1bb8a6a52929af918 to your computer and use it in GitHub Desktop.
Snippet to play sound in Windows Phone via XNA Libraries
static SoundEffectInstance sei;
public async static Task PlaySound(string soundPath, bool delay = true)
{
Stream waveFileStream = TitleContainer.OpenStream(soundPath);
SoundEffect se = SoundEffect.FromStream(waveFileStream);
sei = se.CreateInstance();
FrameworkDispatcher.Update();
sei.Play();
if (delay)
await Task.Delay(se.Duration);
sei.Dispose();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment