In the windows8 Developer preview we can use this code to play audio in background:
mediaElement.AudioCategory = AudioCategory.Media;
In the windows8 Customer perview, It seems that we should use AudioCategory.BackgroundCapableMedia instead of AudioCategory.Media
mediaElement.AudioCategory=AudioCategory.BackgroundCapableMedia;
and I also Declare a background task in appxmanifest
<Extension Category="windows.backgroundTasks" EntryPoint="TestApp.App">
<BackgroundTasks>
<Task Type="audio" />
</BackgroundTasks>
</Extension>
but it didn't work for me and the MediaElement will throw an "MF_MEDIA_ENGINE_ERR_SRC_NOT_SUPPORTED“ exception in MediaFailed EventHandler How should I do?
You also need to set up these event handlers:
using Windows.Media;
-
I think that should have it working.