Game Dev

MediaPlayer class

I checked some things about the submission process lately, and I discovered the way I played musics would just help me to fail the certification…

I used to play music that way (not my actual code, it’s just an example) :

SoundEffect soundEffect = content.Load<SoundEffect>("Sounds/mySong");
SoundEffectInstance songInstance = soundEffect.CreateInstance();
songInstance.IsLooped = true;
songInstance.Play();

Well, it worked fine, and I guess using it to play songs on PC or Xbox 360 is not a problem… But the issue is, on a Windows Phone, if the user is playing his own music it will just play both the user’s music and the game music at the same time. And looks like it’s not allowed.

So I read we should use instead the MediaPlayer class to check if the game has the control or not (which means if the user is using the media player or not…). But we still can prompt the user when the application is launching to ask if he would like to hear the game’s music instead of the one he’s listening. Then, I changed it into something like :

if (!MediaPlayer.GameHasControl)
{
   IAsyncResult guide = Guide.BeginShowMessageBox(
   "Warning", "Do you want to play the game's music instead  
   of the one you are listnening ?", new string[] { "YES", "NO" }, 0,
   MessageBoxIcon.Warning, null, null);
   int result = Guide.EndShowMessageBox(guide);
   if (result == 0) // YES    
   {
        Song songInstance = content.Load<Song>("Sounds/mySong");
        MediaPlayer.Play(songInstance);
   }
   else // NO    
   {
   }
}


The other thing is with the MediaPlayer class we can play mp3 songs... I could only play wav with the SoundEffect... Cool then. That's an important improvement !

Source : http://benkane.wordpress.com/2010/11/23/how-to-play-music-in-xna-games-on-windows-phone-7-and-still-pass-cert/
Game Dev

FieldInfo

Did you know that you could get every information on fields contained in a class ? I didn’t know I could…. I should have googled it 6 months before….  😦

FieldInfo[] fields = this.GetType().GetFields();

foreach (FieldInfo fi in fields)
{
Console.WriteLine(fi.Name);
}

Yeah, I’m still a beginner… And I didn’t know about reflexion ! Shame on me !

I need to refactor every gridview in which I put editable data. It’ll make the code more modular (right now each editable parameter registers itself).
I was wondering how to make a generic Clone function. Without using the reflexion, it’s IMPOSSIBLE !

Let’s code.