1

Information on the Windows Phone Audio Playback Agent seems to be somewhat scarce, and the only real article I can find is the one from MSDN.

Unfortunately, the implementation in the sample is not practical for most apps, as they use a static list of AudioTracks contained within the Audio Playback Agent class library. For most apps, I'd imagine they would have a dynamic list of AudioTracks managed within the application's main project (ie. View Model or something similar). The issue here though, is that there doesn't seem to be an effective way for the Audio Playback Agent to communicate with the rest of the application. I know I can register for the BackgroundAudioPlayer.Instance.PlayStateChanged event, but there is no event for SkipPrevious or SkipNext.

Asked simply -- if you manage your AudioTracks outside of the Audio Playback Agent project, how can you handle when a user uses the SkipPrevious/SkipNext buttons on the Universal Volume Control (UVC)?

letstango
  • 789
  • 6
  • 14

1 Answers1

1

You need to move the logic around what tracks to play into the agent (or a library the agent can use). This is necessary as the agent must be abel to run even when the app isn't running.

The only way to track what is happening in the agent from you app is to subscribe to the BackgroundAudioPlayer.Instance.PlayStateChanged event. This will be fired when the universal controls are used.

As you've noted this greatly limits the amount if information you can include in the app (compared with MediaElement, for instance).

Important Be careful that any logic you move into the agent (or a library referenced by the agent) does not use any of the restricted APIs as even if they're in an assembly referenced by the agent and not used the static analysis of the agent done by marketplace certification will cause it to fail.

Matt Lacey
  • 65,560
  • 11
  • 91
  • 143
  • Any thoughts on how to pass the agent a list of songs from the application at run time? I know it has access to IsolatedStorage... But I'm hoping there's a better way than communicating through the disk! – letstango Aug 16 '11 at 23:10
  • @letstango There isn't a good way to do inter-process comms on the phone. IsolatedStorage is the best way to pass information at the moment. Be sure to use appropriate locking on your files. – Matt Lacey Aug 17 '11 at 08:14
  • 2
    A note on interprocess communication: a method I'm using is to serialize an object and put it in the AudioTrack.Tag field which both the foreground app and background app have access to (via BackgroundAudioPlayer.Instance.Track). – shaunmartin Aug 17 '11 at 15:32
  • Oh wow. Didn't even notice that property. Thanks for the heads up @shaunmartin, I'll have to give that a try. Just wish I knew that before I went ahead an implemented it by serializing it through isolated storage (Which btw works too) :) – letstango Aug 18 '11 at 03:46
  • @shaunmartin What do you mean by interprocess communication. I think that both Audio Agent and Main UI is in the same process, but with different thread – onmyway133 Oct 04 '12 at 11:41
  • The fact that the background agent can continue to play audio even when the foreground app is completely killed/stopped/gone leads me to believe they're in separate processes. – shaunmartin Oct 04 '12 at 17:40