Did you know? DZone has great portals for Python, Cloud, NoSQL, and HTML5!
Windows Phone Zone is brought to you in partnership with:

Den works on awesome stuff. He is a sophomore in college, a Microsoft MVP, a Microsoft Student Insider, a technical writer for DZone and a contributing author for Coding4Fun on Channel9. He is maintaining a number of open-source projects on CodePlex and GitHub. Den is a DZone Zone Leader and has posted 388 posts at DZone. You can read more from them at their website. View Full User Profile

Windows Phone tip of the day: MediaLibrary can be tested in the emulator with built-in songs

04.20.2011
Email
Views: 3130
  • submit to reddit
It's so easy to get up and running with your first Windows Phone app!  Just pick up the FREE toolkit from Microsoft, register at AppHub, and start checking out some fundamental tutorials.

Not a lot of developers know this, but the default OS image that is shipped with the Windows Phone Emulator has built-in media content (other than images) - songs. There are three tracks available for testing purposes:

  • Another Melody Song (00:00:31.3930000) by Windows Phone Artist [Pop]
  • Melody Song (00:00:30.4640000) by Windows Phone Artist [Rock]
  • Rhythm Variation (00:00:15.3710000) by Windows Phone Artist [R&B]

To try these out, simly add a reference to Microsoft.Xna.Framework and use the snippet below:

FrameworkDispatcher.Update();
MediaLibrary lib = new MediaLibrary();

foreach (Song s in lib.Songs)
{
    Debug.WriteLine(s.Name + " " + s.Duration + " " + s.Artist);
}

The songs can be played by the static instance of MediaPlayer (also tied to the Xna stack):

MediaPlayer.Play(lib.Songs[0]);

One of the advantages of having actual musical content in the emulator is the possibility to control it like actual device content.

Due to default platform restrictions, playlists cannot be created on the fly. SongCollection instances (required by MediaPlayer to play batches of songs) are also not open, so each song will have to be passed separately in order to be played.

For reference purposes, the media files are located here:

  • My Documents\Zune\Content\0100\00\15.wma (Another Melody Song)
  • My Documents\Zune\Content\0100\00\11.wma (Melody Song)
  • My Documents\Zune\Content\0100\00\17.wma (Rhythm Variation) 
This is in case you have access to an unlocked image and there is a file manager installed.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

The Windows Phone Microzone, which is supported by Microsoft, is your one-stop-shop for news, tutorials, perspectives, and research on the mobile platform that is making waves in smartphone ecosystem.