Question

The MediaLibraryExtensions.GetPathFromToken has 2 parameters (MediaLibrary library, string token) as input. I assume the API returns path of specified media item from media library, The token is associated with the media of interest. However, how do I find out the "token" of the media, say a music file in media library? Could please show me how to figure out the "token" from a given Song? Thanks in advance.

Was it helpful?

Solution

The value of Token is supplied to an application on a query string when that application is registered to extend various parts of the Windows Phone OS, this includes Photo Share Picker, Photo Edit Picker and Auto Launch from a File Association

All the examples use GetPictureFromToken, but you can imagine the same scenario with other media types being 'Launched' via file association.

Here's a sample of how to use token with GetPicturesFromToken

protected override void OnNavigatedTo(NavigationEventArgs e)
{
    // Get a dictionary of query string keys and values.
    IDictionary<string, string> queryStrings = this.NavigationContext.QueryString;

    // Ensure that there is at least one key in the query string, and check whether the "token" key is present.
    if (queryStrings.ContainsKey("token"))
    {
        // Retrieve the photo from the media library using the token passed to the app.
        MediaLibrary library = new MediaLibrary();
        Picture photoFromLibrary = library.GetPictureFromToken(queryStrings["token"]);

        // Create a BitmapImage object and add set it as the image control source.
        BitmapImage bitmapFromPhoto = new BitmapImage();
        bitmapFromPhoto.SetSource(photoFromLibrary.GetImage());
        image1.Source = bitmapFromPhoto;
    }
}

GetPathFromToken should behave in the same way.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top