Adding Background Audio Capability to Windows Store Apps

March 7, 2013

tips word in wood type

If you’re building a Windows Store app that plays audio you have the option of being able to play your app’s audio in the background (i.e. when the app is not running). Over the course of three posts I want to share some tips and tricks you can use for enabling your apps to run audio in the background and make it through the Windows Store certification process.

In this post I’ll show you how to enable background audio in your apps. Essentially there are two things you need to do. First you’ll need to add the capability to your application’s manifest. These can be done via the following steps:

  1. Open your application’s manifest (that’s the Package.appxmanifest file)
  2. Click on the Declarations tab
  3. Select Background Tasks from the Available Declarations drop down and click Add
  4. Check the Audio checkbox and enter either an Entry point or Start page

image

This will result in the following being added to the xml of the manifest

You need to do one more thing in order to make it work. You’ll need to find the MediaElement that will be playing the audio and set its AudioCategory to BackgroundCapableMedia. If you’re doing so in XAML it will look like this:

Congratulations! Your app can now play background audio.

Warning! Your app will not pass certification…yet. To get into the store your app will need to register for media transport controls as well as consider handling sound level notification events. More on those in upcoming posts.

Additional Resources: