次の方法で共有


XNA on the Zune: Playing Sounds & Music

If you’re making a game for the Zune, it’s an obvious feature to be able to play music, integrating the user’s playlist as a soundtrack to the game. XNA Game Studio 3.0 adds some new framework features that makes it easy not only to play music, but also to play one-off sound effects (in .WAV format), eliminating the need to use a full-featured tool like XACT to play simple sounds.

Sound Effects

XNA Game Studio 3.0 introduces a new class called SoundEffect that allows you to quickly and easily play sound effects.

  1. using Microsoft.Xna.Framework.Audio;
  2. Load the SoundEffect using Content.LoadContent<SoundEffect>(path)
  3. Call the Play(); method on the SoundEffect instance.

Playing Music from the User’s Library

There are two important classes for playing media: MediaPlayer and MediaLibrary. MediaPlayer is a static class that eventually manipulates the Zune audio player directly. MediaLibrary is a class you can instantiate that contains a list of songs. Playing music is really easy:

  1. MediaLibrary library = new MediaLibrary();
  2. MediaPlayer.Play(library.Songs[songIndex]);

Easy as pie. The XNA team has done a fantastic job of making it really easy to use media in your games!

Technorati Tags: xna,zune,c#

Comments