Background Audio during connected Standby RRS feed

  • Question

  • I have a Windows 8.1 Store App that should play a list of MP3 files in the background.

    I have setup the MediaElement to be BackgroundCapableMedia, Registered MediaTransportControls and Declared Background Audio capability.

    Yet when I run the app on my Surface RT, after I press the power button on the device, the current song plays till the end and then whatever I do, the app is suspended.

    Do I STILL (in Windows 8.1) have to do the 'two media elements' hack as described here to have real BackgroundCapableMedia?

    Sunday, December 1, 2013 2:50 AM


  • Well, I went ahead and implemented the dual MediaElement technique. Does work! I used a slightly different technique than the JS example, I can't post the code at the moment but the steps are as follows:

    1. My Playlist is bound to a ListView

    2. When the Player state changes I check for the Paused state and then if the position is at the end of the file I initiate a 'PlayNext' that changes the SelectedIndex of the ListView, which in turn plays the next item.

    To accommodate the dual MedialElement weirdness I added the following:

    3. Add a secondary MediaElement and also load the source stream on a low prio thread after the current playlist item has started playing.

    4. Handled the MediaEnded event of the primary Media element. This fires before the Player State change.

    5. As soon MediaEnded of the primary MediaElement fires, I do a Play on the secondary MediaElement and play a dummy file (a file that is essentially 'silent'). So user doesn't hear the secondary MediaElement but Windows is 'coaxed' into letting the app live (instead of getting suspended). The rest of the implementation then continues, the MediaState changed of the Primary element is hit and the next item in the Playlist is picked up.

    There are LOTS of nuances to getting this working right and I am still working on it. All of it needs an entire MSDN article. It is sad that someone forgot to check of the media element's BackgroundCapable flag before suspending an app and we have to do this pile of hacks to work around it!!!


    • Edited by sumitkm77 Thursday, December 12, 2013 1:58 AM Updated workaround
    • Marked as answer by sumitkm77 Thursday, December 12, 2013 1:58 AM
    Sunday, December 1, 2013 9:35 PM