LicenseAcquirer::AcquireLicenseCompleted Event
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
Occurs when the license acquisition completes.
Assembly: System.Windows (in System.Windows.dll)
In offline scenarios, users download a content file before they play it. Because downloading a media file can take time and bandwidth, consider validating the user license before allowing the download, instead of validating when the user attempts playback. The following example shows how to do this.
The following application uses a key identifier and an authentication token to send a license acquisition request to the license server. The license server responds with a license and the URL from which to download the content.
// Called when the user is online and wants to download some protected content. public void GetLicensePreDelivery(string customData, Guid keyId) { Uri licenseServerUrl = new Uri("http://contoso.com/myLicenseServer.asmx"); LicenseAcquirer acquirer = new LicenseAcquirer(); acquirer.ChallengeCustomData = customData; // Set the License URI to proper License Server address. acquirer.LicenseServerUriOverride = licenseServerUrl; acquirer.AcquireLicenseCompleted += new EventHandler<AcquireLicenseCompletedEventArgs>(acquirer_Completed); acquirer.AcquireLicenseAsync(keyId, ContentKeyType.Aes128Bit, Guid.Empty); }
The AcquireLicenseAsync call completes after starting the license acquisition but without waiting for the long content download operation to finish. When the license acquisition actually completes, the delegate that is configured on the AcquireLicenseCompleted event is called. In this example, that is the acquirer_Completed method, and it might look something like in the following example.
public void acquirer_Completed(object sender, AcquireLicenseCompletedEventArgs e) { if (e.Error != null) { // take appropriate action. Might be retrying for instance. } else if (e.Cancelled) { // take appropriate action. Might be nothing. } else { // // We acquired the license successfully, go ahead and download // the content. Note the service decided to stash the content // url in the LicenseAcquirer response custom data. // string contentAcquisitionUrl = e.ResponseCustomData; DownloadContent(contentAcquisitionUrl);