0

I've created an audio player for windows phone, which uses a playlist of songs collected from an external API.

This playlist is saved to both the client app AND the backgroundaudioplayer so that it can continue to play the next track after a song ends even if the app is not running.

However, this API returns source tracks with urls that are actual REDIRECTS to the file to be streamed.

If I attempt to load these directly into the background audio player, I get an exception.

I attempted to workaround this by allowing the client app to do the redirect and capturing the resulting url before passing it to the player, and updating the playlists on both the client and the app.

This works pretty well.

However, if I then navigate away from my app, the background audio agent continues to play, meaning that the mechanism which updates the urls on the client doesn't fire, and the original redirecting urls are loading, crashing the app.

I've attempted to do the same thing on the background audio agent (issuing a HEAD request and getting the resulting uri from the response) but I cannot get this to work; it never returns from the webrequest!

this is the gist of what I'm trying to accomplish:

    try
    {
        var req = WebRequest.Create(src) as HttpWebRequest;
        req.Method = "HEAD";
        req.BeginGetResponse(ar =>
        {
            try
            {
                var response = req.EndGetResponse(ar);
                var uri = response.ResponseUri;
                selectedTrack.BeginEdit();
                selectedTrack.Source = uri;
                selectedTrack.EndEdit();
                player.Track = selectedTrack;
                player.Play();
            }
            catch (Exception ex)
            {

            }
        }, req);
    }
    catch (Exception ex)
    {

    }

but the callback inside never executes, and the program just halts until I kill it.

I'm sure there must be a better way to handle this, but I have found zero documentation about this issue. how in the heck does everyone else handle this?

I've though about firing a timer on the client to just parse through the list and issue requests and update the whole thing on the fly, but this means 100 requests would execute in sequence every time the app launches (since it gets new tracks every time), so this doesn't really seem like a valid solution...

does anyone have any ideas here? they would be much appreciated!

Neil Turner
  • 2,712
  • 2
  • 18
  • 37
SelAromDotNet
  • 4,715
  • 5
  • 37
  • 59

0 Answers0