Click to Rate and Give Feedback
MSDN
MSDN Library
XNA Game Studio
XNA Game Studio 3.1
Programming Guide
Audio
 How To: Play a Sound

  Switch on low bandwidth view
XNA Game Studio 3.1
How To: Play a Sound
Demonstrates how to play a sound.

To play a sound without using XACT, use the SoundEffect or SoundEffectInstance classes. Using these classes is simpler than using XACT and the classes required by XACT.

Because XACT is not available on Zune, the SoundEffect and SoundEffectInstance will be the only option for Zune games.

SoundEffect and SoundEffectInstance are also available for Xbox and Windows XNA games.

The Complete Sample

The code in this topic shows you the technique. You can download a complete code sample for this topic, including full source code and any additional supporting files required by the sample.

Adding a Sound to Your Project

To add a sound to your project

  1. With your XNA Game Studio game loaded in Visual Studio, right-click the Content icon the Solution Explorer pane.

  2. Click Add, and then click Existing Item.

  3. Navigate to the WAV file you want to play, and then select it.

Simple Sound Playing

Declare SoundEffect.

C#
// Audio objects
SoundEffect soundEffect;
string soundName = "kaboom";

Play the sound.

C#
ContentManager contentManager = new ContentManager(this.Services, @"Content\");
soundEffect = contentManager.Load<SoundEffect>(soundName);
soundEffect.Play();
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker