Created
July 25, 2014 18:56
-
-
Save dgkanatsios/bbb1bb8a6a52929af918 to your computer and use it in GitHub Desktop.
Snippet to play sound in Windows Phone via XNA Libraries
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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