Better reaction on the activation by the Universal Volume Control

As most of you know, you can always start or activate the audio application from which the background audio originates by tapping the Universal Volume Control. Have you noticed that it rarely activates the screen you expect? I did!

To be even honest my own audio playing app P | Cast failed here as well. Specially with the secondary tiles. When you’ve activated the app and playback with from the car mode secondary tile, the reactivation by tapping the Universal Volume Control would always launch the main page.

How can we change the page that’s activated through the Universal Volume Control?

We can’t change it really. It’s just how the Universal Volume Control works. It activates the main form. However, it does add something, an URI parameter. It’s adding the parameter tag and the value is equal to the tag you can provide to the Audio Track you ask the Background Audio to play.

So very interesting we should be able to for example activate a details page that’s belonging to the playing track. I did something differently, I wanted to make sure that the last tile that’s used to activate the app (primary or secondary) is used when activated by the Universal Volume Control.

My app already contains an implementation of the UriMapperBase which allows to convert a request URI into a new URI based on my own mapping rules. So I only had to add a specific rule when the URI contains tag=. I would like to remind you that the implementation inside the if-statement can be modified to your own needs.

internal class AssociationUriMapper : UriMapperBase
{
    public override Uri MapUri(Uri uri)
    {
        Debug.WriteLine("MapUri {1}: {0}", uri, DateTime.Now.ToLongTimeString());
        if (uri.ToString().Contains("tag="))
        {
            App currentApp = (App)Application.Current;

            Debug.WriteLine("Activation through Universal Volume Control, so map to: {0}", currentApp.LastActivationUrl);
            if (currentApp.LastActivationUrl != null)
                return currentApp.LastActivationUrl;
            return uri;
        }
        // Eventually add some other mapping rules.
        // Otherwise perform normal launch.            
        return uri;
    }
}
Gravatar