WP7 Tips–Part I– Media File Coding Techniques to help pass the Windows Phone 7 Marketplace Certification Requirements


Developing an application that plays media files on a Windows Phone 7 Device seems fairly straight forward.  However, what can make this a bit frustrating are the necessary requirements in order to pass the WP7 marketplace requirements so that your application can be published.  If you are new to this development, be aware of these common challenges that are likely to be made.  Below are some techniques and recommendations on how optimize your application to handle playing MP3 and/or WMA files that needs to adhere to the marketplace requirements.


Windows Phone 7 Certification Requirements

Windows Phone 7 Developers Blog


Some common challenges are:

  • Not prompting the user if another media file is playing in the background before playing your media file
  • Not allowing the user to control the volume
  • Not allowing the user to mute the sound
  • Not allowing the media to be interrupted by a phone call 

To keep this as simple as possible I am only going to focus on what “not to do” and what “to do” in order to implement a simple media solution.

Things you will need or may be useful to you before you begin:

Visual Studio 2010

Visual Studio 2010 Feature Packs

Windows Phone 7 Developer Tools

  • Visual Studio 2010 Express for Windows Phone
  • Windows Phone Emulator Resources
  • Silverlight 4 Tools For Visual Studio
  • XNA Game Studio 4.0
  • Microsoft Expression Blend for Windows Phone


Please keep in mind you do not need all of these downloaded and installed, it is just easier to have all that you need now rather than add them on later.


Objective Summary

Create a Windows Phone 7 – Windows Media Sample Application.  The application will implement many of the required features in order to pass the WP7 marketplace certification requirements in order to publish an application to WP7’s marketplace.

(Disclaimer: I am not trying to indicate that this application will always pass as the requirements may change or be updated)


Step 1: – Create a New Windows Phone 7 Project



Step 2: – Update the Title and Application Name of your WP7 Application

For this example I changed:

the Title to: “DOTNETNUZZI WP7 MEDIA SAMPLE - v1.00

and the Page Title to:  “media magic”.



I also updated the background.


Step 3: – XAML - Media Element Preparation and Best Practice

Before we begin the next step I just wanted to point out a few things that you should not do as a best practice when developing an application for WP7 that is playing music.  Please keep in mind that these requirements are not the same if you are playing Sound Effects and are geared towards playing media in the background.


If you have coded this – be prepared to change it:



To avoid a failure from the market place remove all of your media source elements from your XAML or simply create them dynamically.  To keep this simple we will remove the source and set the AutoPlay property to false to ensure that there are no media elements are active when the application is started.

Proper example of the media element with No Source:


Some Additional Settings - Add XAML Support for a Mute Button



Step 4: – Boolean to handle toggle of Mute Feature


Step 5: – Add Event Handler for Main Page Load



Step 6: – Add Reference to the XNA Framework



Step 7: – Add two Using Statements to Resolve the Namespace of Media and the Application Bar

using Microsoft.Xna.Framework.Media;
using Microsoft.Phone.Shell;



Step 8: – Add the Method to Check the Media State as Shown Below



Step 9: – Add Code to Mute the Media File


Step 10: – Add Code to Play the Media File

//if the state of the media has been checked you are good to go.


If we tried to perform this operation at this point you will receive the following error:

System.InvalidOperationException was unhandled Message=FrameworkDispatcher.Update has not been called. Regular FrameworkDispatcher.Update calls are necessary for fire and forget sound effects and framework events to function correctly.

See http://go.microsoft.com/fwlink/?LinkId=193853 for details.

       at Microsoft.Xna.Framework.FrameworkDispatcher.AddNewPendingCall(ManagedCallType callType, UInt32 arg)
       at Microsoft.Xna.Framework.UserAsyncDispatcher.HandleManagedCallback(ManagedCallType managedCallType, UInt32 managedCallArgs) at Microsoft.Xna.Framework.UserAsyncDispatcher.AsyncDispatcherThreadFunction()


It is not recommended that you just add the FrameworkDispatcher.Update(); call before playing the media file.

It is recommended that you implement the following class to your solution and implement this class in the app.xaml.cs file.


Step 11: – Add FrameworkDispatcher Features

I recommend creating a class named XNAAsyncDispatcher and adding the following code:



After you have added the code accordingly, you can now implement this into your app.xaml.cs file as highlighted below.




If you application sound file is not playing make sure you have the proper “Build Action” set such as Content.


Running the Sample

Now that we have some of the foundation created you should be able to run the application successfully.  When the application launches your sound options should be set accordingly when the “checkMediaState” method is called.  As a result the application will properly setup the media options and/or alert the user accordinglyper the certification requirements. 

In addition, the sample also shows a quick way to mute the sound in your application by simply removing the URI source of the media file. 

If everything successfully compiled the application should look similar to below.


                <sound playing>



At this point we have a fully functional application that provides techniques on how to avoid some common challenges when working with media files and developing applications for Windows Phone 7.  The techniques mentioned above should make things a little easier and helpful in getting your WP7 application approved and published on the Marketplace. 

The next blog post will be titled:

WP7 Tips–Part II - How to write code that will pass the Windows Phone 7 Marketplace Requirements for Themes (light and dark).

If anyone has any questions or comments please comment on this blog. 


  • In step 3 you say: " these requirements are not the same if you are playing Sound Effects". Why is that? If I have a button that plays the sound of dog bark, do I not have to check if media is playing?

  • When playing media files using the media element the media is playing in the background and becomes the only media playing at that time. Similar to if you are playing a music file. You can only play one at a time. Therefore you need to follow certain requirements when playing media such as music.

    However, if you play a sound as a sound effect, the sound will play in addition to the background music playing so you do not need to worry about these requirements. The libraries are also different such like below:

    1. var stream = TitleContainer.OpenStream("soundeffect.wav");
    2. var effect = SoundEffect.FromStream(stream);
    3. FrameworkDispatcher.Update();
    4. effect.Play();

    Hope this helps.

  • Do you mind if I quote a couple of your articles as long as I provide credit and sources back to your webpage? My website is in the very same area of interest as yours and my users would really benefit from a lot of the information you provide here. Please let me know if this alright with you. Regards!

  • Amazing! This blog looks exactly like my old one! It's on a totally different subject but it has pretty much the same page layout and design. Great choice of colors!

  • I seldom create responses, however i did a few searching
    and wound up here WP7 Tips–Part I– Media File Coding Techniques to
    help pass the Windows Phone 7 Marketplace Certification Requirements
    - Sean Iannuzzi's Blog. And I actually do have 2 questions for you if it's
    allright. Is it simply me or does it look like some
    of these responses come across like left by brain dead individuals?
    :-P And, if you are posting at other online social sites,
    I'd like to follow everything new you have to post. Would you make a list of the complete urls of all your community sites like your linkedin profile, Facebook page or twitter feed?

  • Find Blackberry pin code from girls and boys, to chat with dem in the Blackberry chat and get their pin or number.

Comments have been disabled for this content.