Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Building your First Mobile Game using XNA 4.0

You're reading from   Building your First Mobile Game using XNA 4.0 A fast-paced, hands-on guide to building a 3D game for the Windows Phone 7 platform using XNA 4.0

Arrow left icon
Product type Paperback
Published in Jan 2013
Publisher Packt
ISBN-13 9781849687744
Length 158 pages
Edition 1st Edition
Languages
Arrow right icon
Authors (2):
Arrow left icon
Thomas Goussaert Thomas Goussaert
Author Profile Icon Thomas Goussaert
Thomas Goussaert
Brecht Kets Brecht Kets
Author Profile Icon Brecht Kets
Brecht Kets
Arrow right icon
View More author details
Toc

Playing a song


Sometimes you want to play a song instead of a sound, for instance background music for a game. The MediaPlayer class is a static class that exposes functionality to play songs. This class is also more advanced than the previous classes, in the sense that you can make it act like a true media player, and play, pause, resume, mute, repeat, shuffle, and so on. And of course, it is possible to play songs from the user's media library. But let's start simple. We can load a song the usual way, via the content manager. Note that we have to use a different processor, being the Song processor. Game Studio 4.0 selects a default processor based on file type, that is Song for MP3 files. After loading the song, we can play it using the media library:

Song song = game.Content.Load<Song>("MySong");
MediaPlayer.Play(song);

The previous code would work perfectly, but it has some issues. First of all, if we were to submit a game with this code to the Windows Phone Marketplace, it would...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image