Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

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

DZone's Guide to

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

· Mobile Zone
Free Resource

Discover how to focus on operators for Reactive Programming and how they are essential to react to data in your application.  Brought to you in partnership with Wakanda

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.

Learn how divergent branches can appear in your repository and how to better understand why they are called “branches".  Brought to you in partnership with Wakanda

Topics:

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

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

X

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

{{ parent.tldr }}

{{ parent.urlSource.name }}