开发者

WP7 - Controlling the BackgroundAudioPlayer form the Foreground app

开发者 https://www.devze.com 2023-04-13 07:15 出处:网络
All the samples I have seen so far are of AudioPlaybackAgents with hardcoded lists of songs. I need to control the list from the foreground app. Seems like an obvious requirement to me.

All the samples I have seen so far are of AudioPlaybackAgents with hardcoded lists of songs.

I need to control the list from the foreground app. Seems like an obvious requirement to me.

The BackgroundAudioPlayer.Instance.Track api makes it look like you can add a Track directly to the BackgroundPlayer, from the Foreground app, and they shou开发者_如何学Pythonld just play. That does not seem to work

What is the background agent going to be doing if the "playlist" is just a single track?

If the playlist is multiple tracks and the Agent is being called on its callbacks to move through the list what is the suggested way of communicating the PlayList from the foreground app to the Agent?

TIA

Pat Long


I've found that the interface between the BackgroundAudioPlayer (BAP) and foreground applications is quite possibly the most ill-conceived piece of "engineering" in the Windows Phone 7.x SDK. IsolatedStorage doesn't really work for me because my app could download many files and only play a few at a time in a "play list". Should I temporarily copy those files to a "special" location in IsolatedStorage just so the agent can read the playlist from there? At 10 to 20MB a pop, I don't think so. Also, if I want to use the background transfer service -- which works pretty well, btw -- to incrementally add files to the playlist, how would I go about telling the agent to go load up more tracks as they are downloaded? Short of settling on some convention to get the tracks created in the right order, it can't be done.

Tried to use static members on the agent to add tracks to a playlist (as they suggest in the docs), and...umm...yeah, that is just a non-starter.

What I have settled for now is to manage the playlist in the foreground app and feed tracks one by one to the BAP based on the user's actions. Problem is that this doesn't work with the BAP controls shown on the lock screen. Nor does it seem to handle the TrackEnded event consistently. I am within a hair's breadth of just using the MediaElement and forgo background audio all together.

I hope whoever invented this farce of an API is not involved in future versions of WP.


If you're working with playlists the assumption is that these will added to/updated even if the app is not in the foreground. In this case the agent must be able to manage the playlist.

If you're just playing a single track at a time then the background agent just needs to keep the track playing while your app is not in the foreground.

Communicating between the app and the agent can be tricky at best. The simplest way to communicate is to create files in Isolated Storage that one writes and the other reads (and then deletes) or via a database.


AudioTrack audioTrack =
                new AudioTrack(new Uri("shared\\transfers\\1.mp3", UriKind.RelativeOrAbsolute), null,
                                null,
                                null,
                                null,
                                null,
                                EnabledPlayerControls.Pause);
 BackgroundAudioPlayer.Instance.Track = audioTrack;
                 BackgroundAudioPlayer.Instance.Play();
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号