The right way to play audio in the background in Windows Phone 8 is pretty straightforward, but only if you start from a "Windows Phone Audio Playback Agent" template.
Instructions from MSDN are here.
I'm trying to figure out how to insert that into a Xamarin Forms app, however.
The only place you seem to "register" the BackgroundServiceAgent in Windows Phone is in the WMAppManifest.xml in the app's Properties folder, which you then backhandedly invoke with
BackgroundAudioPlayer.Instance.Play();, which apparently maps up to the agent you've registered with code like what's below.
<Tasks> <DefaultTask Name="_default" NavigationPage="MainPage.xaml" /> <ExtendedTask Name="BackgroundTask"> <BackgroundServiceAgent Specifier="AudioPlayerAgent" Name="MyAudioPlaybackAgent" Source="MyAudioPlaybackAgent" Type="MyAudioPlaybackAgent.AudioPlayer" /> </ExtendedTask> </Tasks>
But in my Xamarin Forms app, I get a UI instead of raw XML:
Anything obvious I'm missing?
Is there a tutorial somewhere on playing sound in the three mobile platforms? I found stuff like playing system sounds in iOS, but I think that's just for an in-app alert, and that I need to figure out AVAudioPlayer to get background audio working "for reals". Neither of these (WP or iOS) seem particularly obvious in XamForms, but playing backgrounded music seems like it should be a common tutorial... ?
EDIT: Looks like you can just open your XamForm solution's Windows Phone project's WMAppManifest.xml file in ye old text editor of your choice, paste in the
Task jive from above, and not have it complain. Hoping it's that easy.