Over a million developers have joined DZone.

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

· Mobile Zone

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.
Topics:

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}