Using EasyXnaAudio is pretty simple. Follow these steps to setup EasyXnaAudio with your project.

1. Add EasyXnaAudioComponent.cs to your XNA Game Studio project. (Optionally, wrap it in a namespace.)
2. In your Game constructor, create a new EasyXnaAudioComponent object and add it to your Game's component list.
3. In your LoadContent method, call LoadSong and LoadSound to load the songs for use.
4. Call PlaySong or PlaySound to use the component.

Here is a skeleton Game class that demonstrates how it works:

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;

class Game1 : Game
   GraphicsDeviceManager graphics;
   EasyXnaAudioComponent audio;
   bool enterPressed = false;

   public Game1()
      graphics = new GraphicsDeviceManager(this);
      Content.RootDirectory = "Content";

      audio = new EasyXnaAudioComponent(this);

   protected override void LoadContent()

   protected override void Update(GameTime gameTime)
      KeyboardState keyState = Keyboard.GetState();
      if (keyState.IsKeyDown(Keys.Space))
      if (!enterPressed && keyState.IsKeyDown(Keys.Enter))
      enterPressed = keyState.IsKeyDown(Keys.Enter);

Note that setting the Enabled property of the component to false will cause all songs and sounds to pause. Setting Enabled back to true will resume all songs and sounds.

Last edited Dec 10, 2010 at 5:19 PM by Rainault, version 7


No comments yet.