Play in background ?

Topics: Windows 8 Xaml
Sep 18, 2012 at 7:28 AM

Hello.

It's possible to keep playing (for example remote MP3) while application is NOT active ?

 

Thank you
Andrew

Coordinator
Sep 18, 2012 at 9:19 PM

Andrew, the AudioCategory property will determine the behavior of media while the app is inactive.

http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.controls.mediaelement.audiocategory

http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.media.audiocategory

BackgroundCapableMedia is what you want.

Regards, Tim

Oct 19, 2012 at 3:13 AM
Edited Oct 19, 2012 at 4:10 AM

I have set the property to BackgroundCapableMedia, but when I go to another application, the player stops playing. Have I done something wrong or can an app running in debug mode not fire this capability?

[edit]
From reading around the Internet, there are some app settings that need to be set to allow media to play background.  I have set Task Type="audio" in the extensions but still no dice.

Oct 19, 2012 at 7:05 AM

I think you must set some events to your player :

  MediaControl.PlayPressed += ....;
  MediaControl.PausePressed += ...;
  MediaControl.PlayPauseTogglePressed += ....;
  MediaControl.StopPressed += ...;

 

Andrew

Oct 20, 2012 at 2:01 AM

When I try to add that code, I receive the error:

'Public Shared Event PlayPressed(sender As Object, e As Object)' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event.

I also cannot set the Subs to handle the event directly because the operating system does not declare the public object WithEvents.

Nov 4, 2012 at 6:16 PM

I also added the media element but when suspending the application it stops playing, can some one help with this ?

(Like in a step by step tutorial)

Apr 13, 2013 at 7:26 AM
seems like old thread but still...here is the guide: http://msdn.microsoft.com/en-us/library/windows/apps/xaml/jj841209.aspx
Coordinator
Apr 15, 2013 at 5:46 PM
Fyi: the v1.1 release introduced a new plugin called MediaControlPlugin. This plugin automatically wires up the MediaControl events for you so you no longer have to perform this step. Or, if you have your own code in place already and want to continue using it instead of the built in plugin, you can easily disable the plugin by setting it's IsEnabled property to false.
        public MainPage()
        {
            this.InitializeComponent();
            player.Initializing += player_Initializing;
        }
 
        void player_Initializing(object sender, MediaPlayerDeferrableEventArgs e)
        {
            var mediaControlPlugin = player.Plugins.OfType<MediaControlPlugin>().First();
            mediaControlPlugin.IsEnabled = false;
        }