How to play background music online in Windows 8

In my application I use UI MediaElement. But when I press 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 the source of the 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!

+8
c # windows-8
source share
2 answers

For the Metro / WinRT application to play audio in the background, the application needs the following:

  • A MediaElement controls that:
  • Use the MediaControl object to capture at least the following. If necessary, you can handle other events and properties, but the following is required to play the background.
  • Add audio to the list of supporting background tasks in the application manifest. The phenomenon is usually called Package.appxmanifest . Select it in Solution Explorer, go to the "Ads" tab and select "Audio" as shown:

enter image description here

For more information on capturing hardware buttons (such as playing / pausing on a keyboard), see the Vehicle Management Guide and Quick Start Guide to create a media player for more information.

+10
source share

That would be my first answer. Make sure you set AudioCategory="BackgroundCapableMedia" in your XAML as follows:

 <MediaElement x:Name="backgroundMusic" AutoPlay="True" AudioCategory="BackgroundCapableMedia" Source="mms://betafm.santafe-conicet.gov.ar:1175"> </MediaElement> 

Hope this helps!

+1
source share

All Articles