SoundEffectPlayer class

This class is used to play SoundEffect objects using the XNA integration. The player must live long enough for the sound effect to play so it is common to have it scoped outside a method. For example:


public partial class MediaPage : PhoneApplicationPage
{
  // ...

  SoundEffectPlayer _player = null;

  private void playButton_Click(object sender, RoutedEventArgs e)
  {
    var resource = Application.GetResourceStream(new Uri("alert.wav", UriKind.Relative));
    var effect = SoundEffect.FromStream(resource.Stream);
    _player = new SoundEffectPlayer(effect);
    _player.Play();
  }
}

Last edited Mar 5, 2011 at 7:55 AM by TheADOGuy, version 3

Comments

No comments yet.