Metro, Windows 8, WinRT

metro background audio c# (consumer preview)

Peter Daukintis

Some changes occurred in the consumer preview release of Windows 8 regarding background audio; the steps required to get it working are outlined in this forum post

The steps are

  • Create a MediaElement and set it’s AudioCategory property to ‘BackgroundCapableMedia’
    <MediaElement x:Name="myMedia"
                  Source="/Assets/Sleep Away.mp3"

  • Update the app manifest to declare Background Tasks of types ‘Audio’ and ‘Control Channel’
  • Implement event handlers for
    • MediaControl.PlayPressed
    • MediaControl.PausePressed
    • MediaControl.PlayPauseTogglePressed
    • MediaControl.StopPressed


public BlankPage()
    MediaControl.PlayPressed += MediaControl_PlayPressed;
    MediaControl.PausePressed += MediaControl_PausePressed;
    MediaControl.PlayPauseTogglePressed += MediaControl_PlayPauseTogglePressed;
    MediaControl.StopPressed += MediaControl_StopPressed;

private void MediaControl_StopPressed(object sender, object e)

private void MediaControl_PlayPauseTogglePressed(object sender, object e)

private void MediaControl_PausePressed(object sender, object e)

private void MediaControl_PlayPressed(object sender, object e)

The media transport event handlers which need to be implemented are detailed here


Here’s a working sample project.!440&parid=4F1B7368284539E5!123‏

UPDATE: I have updated this for the Release Preview (see

Tagged , , , , , , ,

12 thoughts on “metro background audio c# (consumer preview)

  1. Hi, I downloaded your sample project but found the “pause” button didn’t work when I press the volume button. Also, I followed the steps you described and ran into the same problem. confused…

    1. Probably because it’s hitting this MediaControl_PlayPauseTogglePressed handler which has no code in it? That was the case for me so I simply put toggling code in there based on the Status.

      1. hi, Can you share which code you added for toggling. I am trying to mymedia inside that event and it is giving me UI Thread Error.

      2. @tarun, yes you will get that problem, the event doesn’t come from the UI thread.
        You need to schedule it on the dispatcher….

        private void MediaControl_PlayPauseTogglePressed(object sender, object e)
        Dispatcher.InvokeAsync(CoreDispatcherPriority.High, (s, args) =>
        if (CurrentState != MediaElementState.Playing)
        this, null);

  2. Hi,

    Unfortunately, this sample does not work for the Release Preview. I have built a sample using the same settings in RP but the media pauses working when you navigate to another app i.e. does not play in background. Any ideas?

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.