Reputation: 627
In my application, I use UI MediaElement. But when i click the Windows key, the music stops.
I tried using:
MediaControl.PlayPressed += MediaControl_PlayPressed;
MediaControl.PausePressed += MediaControl_PausePressed;
MediaControl.PlayPauseTogglePressed += MediaControl_PlayPauseTogglePressed;
MediaControl.StopPressed += MediaControl_StopPressed;
I set source MediaElement:
media.Source = new Uri("http://stream-hq.mp3.zdn.vn/fsgggsfdlwjglwjAAAAA/2a3f830202ea6d29bc7c5a5146401566/4ff5620a/2011/12/27/a/4/a4fcc199a184a93cfeb0fe35642c53bf.mp3", UriKind.RelativeOrAbsolute);
Please help me!
Upvotes: 8
Views: 4529
Reputation: 14386
For a Metro/WinRT app to play audio in background, the app needs the following:
Package.appxmanifest
. Select it in the Solution Explorer, go to the Declarations tab and check "Audio" as shown:See the Transport Controls Guide for more info about capturing hardware buttons (e.g. play/pause on the keyboard) and the quickstart guide for creating a media player for more info.
Upvotes: 10
Reputation: 11
This would be my first answer. Make sure you set AudioCategory="BackgroundCapableMedia"
in your XAML like this:
<MediaElement x:Name="backgroundMusic"
AutoPlay="True"
AudioCategory="BackgroundCapableMedia"
Source="mms://betafm.santafe-conicet.gov.ar:1175">
</MediaElement>
Hope it helps!
Upvotes: 1