Play audio in Windows 8 apps without Media element?
Asked Answered
K

1

6

I want to play audio in a Windows 8 app without using the Media element. Media Element needs to be attached to the Visual Tree of each page. Since all pages in my app use background audio, I have to attach the MediaElement in the App frame. The whole thing kind of sucks. I will appreciate if someone can provide me pointers to play audio in Windows 8 app without this Media element non-sense.

Keiko answered 1/5, 2013 at 11:20 Comment(3)
+1 thank you for this question because I would do it sooner or later. I thought of using DirectX but I have no experience with it so I don't know if it is easily doable.Muggins
Have you looked at this? #9565044Lindley
The question does not help me. The MediaElement should still be added to the XAML to play audio. I am trying to play audio without any changes to the XAML.Keiko
F
1

You need to set the property on your MediaElement:

<MediaElement x:Name="myMedia" AudioCategory="BackgroundCapableMedia />

The content of this MediaElement will then play even on other pages and when your app is suspended. You also need to set a capability Background Tasks -> Audio in the app manifest that your app supports background audio.

Nice tutorial how to use this feature is here:
Background Audio c# Metro
or here:
Play audio in background by use BackgroundCapableMedia

Follmer answered 18/5, 2013 at 9:40 Comment(1)
MediaElement is a pain. You have to add it to the XAML. Without adding it in the XAML you cannot play audio. I need it for each and every page.Keiko

© 2022 - 2024 — McMap. All rights reserved.