Condividi tramite


MediaLicense Class

Microsoft Silverlight will reach end of support after October 2021. Learn more.

An instance of the license class representing a logical license.

Inheritance Hierarchy

System.Object
  System.Windows.Media.MediaLicense

Namespace:  System.Windows.Media
Assembly:  System.Windows (in System.Windows.dll)

Syntax

'Declaration
Public Class MediaLicense
public class MediaLicense

The MediaLicense type exposes the following members.

Properties

  Name Description
Public property ExpirationDate Gets the expiration date of the MediaLicense class instance.
Public property KeyId Gets the content key identifier of the MediaLicense.
Public property UplinkKeyId Gets the uplink key identifier of the highest license in the chain with an uplink key identifier.
Public property Usable Gets a value that indicates whether the license or license chain is usable for playback.

Top

Methods

  Name Description
Public method Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected method Finalize Allows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
Public method GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public method ToString Returns a string that represents the current object. (Inherited from Object.)

Top

Remarks

A logical license could be an actual license chain (leaf plus root), a simple license, or only a partial chain. The latter case can happen if the root license was queried for directly or if there was an issue with the root license and only the leaf is available (root expired or missing).

Examples

You can check whether a license or license chain has expired by iterating through all the licenses (MediaLicense objects) on the persistent license store. If any licenses need to be updated, you can add logic to attempt to connect to the licensing server and make necessary updates, prompt the user for payment, and so on.

The following example shows how to check whether a subscription license needs to be renewed.

private void CheckSubscriptionRootForRenewal(Guid parentKeyId,
                                             Uri licenseServerUrl)
{

    DateTime renewalDate = DateTime.Now.AddDays(5);

    // Query the licensemanager to see if we have a usable root license
    IEnumerable<MediaLicense> myLicenses = LicenseManagement.SelectLicenses(parentKeyId);

    bool renewRoot = true;

    foreach (MediaLicense ML in myLicenses)
    {
        // If the license expires within the next 5 days,
        // renew the subscribtion by requesting a new root license.
        if ((ML.Usable) &&
            (ML.ExpirationDate > renewalDate))
        {
            renewRoot = false;
            break;
        }

    }

    if (renewRoot)
    {
        LicenseAcquirer acquirer = new LicenseAcquirer();
        acquirer.LicenseServerUriOverride = licenseServerUrl;
        acquirer.AcquireLicenseCompleted += new EventHandler<AcquireLicenseCompletedEventArgs>(acquirer_Completed);
        acquirer.AcquireLicenseAsync(parentKeyId, ContentKeyType.Aes128Bit, Guid.Empty);
    }

In this example, you are iterating through all the MediaLicense instances in the persistent license store. A MediaLicense instance could be any of the following:

  • A license chain (leaf plus root)

  • Single simple license

  • Single leaf license (root does not exist)

  • Single root license (root is queried directly)

The following function could be used to filter the list of content shown to the user in a list of possible playback choices, especially if the user is offline and cannot get new licenses. It could also be used to decide whether to get a license before going offline. For a subscription customer, the CheckSubscriptionRootForRenewal function (from the previous example) should be called first if the user is online.

public bool IsUsableLicenseAvailableForContent(System.IO.Stream contentFile)
{
    bool returnValue = false;

    IEnumerable<MediaLicense> myLicenses = LicenseManagement.SelectLicenses(contentFile);


    foreach (MediaLicense ML in myLicenses)
    {
        if (ML.Usable)
        {
            returnValue = true;
            break;
        }
    }

    return returnValue;
}

Version Information

Silverlight

Supported in: 5, 4

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.