Zune.net
Started by FallenArms3 at 10/20/2009 00:03:21. Topic has 3 replies.
sort posts by:oldest / newest

Join Date: 9/16/2009 00:29:46

Posts: 35

10/20/2009 00:03:21
Playing sound effects in XNA 3.1 Zune API?
Call me crazy, but every documented method of playing sound effects has lead me to a dead end when I'm trying to develop my application.  This app is RELIANT on sound, so I really need it to work.  Can someone please familiarize me with how to load sound content into the application and then play it (and possibly even initialize it)?  This is driving me insane.

By the way, this is XNA 3.1 Zune Extensions, and I'm developing for the Zune HD.
0 helpful ratings, 0 not helpful ratings
Was this post helpful? Yes No

Join Date: 10/20/2009 05:01:35

Posts: 2

10/20/2009 05:06:09
re: Playing sound effects in XNA 3.1 Zune API?
Very simply, it is like this.

First, add a sound file (Wav, wma or mp3) to your content folder with the name "Sound".

At the top of Game1 under "SpriteBatch spritebatch;" put the lines

SoundEffect effect;
bool hasPlayed = false;

then in LoadContent under the "spriteBatch..." line type.

Content.Load<SoundEffect>("Sound");

then in the update method :

if(!hasPlayed)
{
hasPlayed = true;
effect.Play();
}

Simply call effect.Play() whenever you need to play the sound.


0 helpful ratings, 0 not helpful ratings
Was this post helpful? Yes No

Join Date: 9/16/2009 00:29:46

Posts: 35

10/20/2009 21:04:58
re: Playing sound effects in XNA 3.1 Zune API?
Thank you for replying.  I've since had someone explain things to me (though slightly differently), and it SEEMS to be alright, except for one big error...

First of all, here is a PasteBin of my code at the moment: http://pastebin.com/m3e50f0

When I try to Debug the program on my Zune, I get this error when trying to load a sound:

"An unhandled exception of type 'Microsoft.Xna.Framework.Content.ContentLoadException' occurred in Microsoft.Xna.Framework.dll

Additional information: Error loading "\Audio\Mp3\1A or 4A.mp3". Cannot open file."

Why would the Zune not be able to open Mp3 files?  I get the feeling the problem lies elsewhere in my code, which is why I put the whole thing on PasteBin.  If anyone can take a look at it and tell me what's wrong, I'd be very grateful.

0 helpful ratings, 0 not helpful ratings
Was this post helpful? Yes No

Join Date: 10/20/2009 05:01:35

Posts: 2

10/21/2009 04:12:49
re: Playing sound effects in XNA 3.1 Zune API?
The problem here is that your adding .mp3 to the name of the file.

When you add any asset to an XNA games content folder, XNA turns it into its own format.

On the line that you load the content, simply remove the .mp3 from the filename.

Also, is there any reason your using a different ContentManager?

i.e
contentManager.Load<SoundEffect>...

you could just use
Content.Load<SoundEffect>...
shorter and will use less resources.

If you want I can edit your pastebin, just post back if you do.


0 helpful ratings, 0 not helpful ratings
Was this post helpful? Yes No