[Background Audio] How to dynamically add link

Nov 27, 2015 at 2:32 AM
Edited Nov 27, 2015 at 2:37 AM
I would like to add the background audio link to the TrackManager Source dynamically because the link changes from time to time.

VS 2013
Windows Phone 8.1

Hope for some advice. Thanks!
Dec 12, 2015 at 12:44 PM
TrackManager needs to be customized anyway since it is just a hard coded list of MediaTrack instances. As long as the application can provide MediaPlayerManager with an immutable IList<MediaTrack> it should be simple enough. If your version, say, loaded the tracks from a local database or from a remote list of tracks or what-not, when it starts up then it should work pretty much the same. If an async call is needed to initialize a custom TrackManager, then the right place to do so is probably in BackgroundAudioRun.ExecuteAsync(), right before it instantiates MediaPlayerManager.

If you need to dynamically update the playlist during playback, then MediaPlayerManager will need to be updated. There is code like this:
    for (var i = 0; i < _tracks.Count; ++i)
        var track = _tracks[i];
that could misbehave if the number of tracks changed between when _tracks.Count is checked and when _tracks[i] is read.

A more general solution would probably be something like an interface that provided a current MediaTrack, some way to move to another track, and a safe way to refresh things.