From c855c4bc9bcc98ab2e516342b69252c9df6cee42 Mon Sep 17 00:00:00 2001 From: "sxian0613@gmail.com" Date: Tue, 15 Feb 2022 13:01:26 -0800 Subject: [PATCH] Upgrade BasicWidevine sample to track 2 SDK. --- ContentProtection/BasicWidevine/pom.xml | 64 ++-- .../src/main/java/sample/BasicWidevine.java | 282 ++++++++---------- 2 files changed, 156 insertions(+), 190 deletions(-) diff --git a/ContentProtection/BasicWidevine/pom.xml b/ContentProtection/BasicWidevine/pom.xml index b981cf4..e8987b9 100644 --- a/ContentProtection/BasicWidevine/pom.xml +++ b/ContentProtection/BasicWidevine/pom.xml @@ -1,5 +1,5 @@ - + 4.0.0 sample BasicWidevine @@ -14,44 +14,45 @@ 1.1.1 - com.microsoft.azure.mediaservices.v2020_05_01 - azure-mgmt-media - 1.0.0-beta + com.azure.resourcemanager + azure-resourcemanager-mediaservices + 1.1.0-beta.2 - com.microsoft.rest - client-runtime - 1.6.8 + commons-codec + commons-codec + 1.15 - com.microsoft.azure - azure-client-authentication - 1.6.8 + com.azure + azure-messaging-eventhubs + 5.10.3 - com.microsoft.azure - azure-arm-client-runtime - 1.6.8 + com.azure + azure-messaging-eventhubs-checkpointstore-blob + 1.10.2 - com.microsoft.azure - azure-client-runtime - 1.6.8 + com.azure + azure-core + 1.21.0 - com.fasterxml.jackson.core - jackson-core - 2.9.4 + com.azure + azure-identity + 1.4.0 - com.fasterxml.jackson.core - jackson-databind - 2.10.0.pr1 + com.azure + azure-sdk-bom + 1.0.3 + pom - com.fasterxml.jackson.core - jackson-annotations - 2.9.0 + com.azure + azure-storage-blob + 12.14.1 io.jsonwebtoken @@ -70,12 +71,6 @@ 0.10.5 runtime - - com.azure - azure-sdk-bom - 1.0.3 - pom - org.slf4j slf4j-api @@ -86,11 +81,6 @@ slf4j-log4j12 1.7.5 - - com.fasterxml.jackson.core - jackson-databind - 2.10.0.pr1 - diff --git a/ContentProtection/BasicWidevine/src/main/java/sample/BasicWidevine.java b/ContentProtection/BasicWidevine/src/main/java/sample/BasicWidevine.java index 05cf051..dc8599c 100644 --- a/ContentProtection/BasicWidevine/src/main/java/sample/BasicWidevine.java +++ b/ContentProtection/BasicWidevine/src/main/java/sample/BasicWidevine.java @@ -8,7 +8,6 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; -import java.util.NoSuchElementException; import java.util.Scanner; import java.util.UUID; import java.util.stream.Collectors; @@ -23,42 +22,18 @@ import com.azure.storage.blob.BlobContainerAsyncClient; import com.azure.storage.blob.BlobServiceAsyncClient; import com.azure.storage.blob.BlobServiceClientBuilder; -import com.azure.storage.blob.models.ListBlobsOptions; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.microsoft.aad.adal4j.AuthenticationException; -import com.microsoft.azure.AzureEnvironment; -import com.microsoft.azure.credentials.ApplicationTokenCredentials; -import com.microsoft.azure.management.mediaservices.v2020_05_01.ApiErrorException; -import com.microsoft.azure.management.mediaservices.v2020_05_01.Asset; -import com.microsoft.azure.management.mediaservices.v2020_05_01.BuiltInStandardEncoderPreset; -import com.microsoft.azure.management.mediaservices.v2020_05_01.ContentKeyPolicy; -import com.microsoft.azure.management.mediaservices.v2020_05_01.ContentKeyPolicyOption; -import com.microsoft.azure.management.mediaservices.v2020_05_01.ContentKeyPolicyProperties; -import com.microsoft.azure.management.mediaservices.v2020_05_01.ContentKeyPolicyRestriction; -import com.microsoft.azure.management.mediaservices.v2020_05_01.ContentKeyPolicyRestrictionTokenKey; -import com.microsoft.azure.management.mediaservices.v2020_05_01.ContentKeyPolicyRestrictionTokenType; -import com.microsoft.azure.management.mediaservices.v2020_05_01.ContentKeyPolicySymmetricTokenKey; -import com.microsoft.azure.management.mediaservices.v2020_05_01.ContentKeyPolicyTokenClaim; -import com.microsoft.azure.management.mediaservices.v2020_05_01.ContentKeyPolicyTokenRestriction; -import com.microsoft.azure.management.mediaservices.v2020_05_01.ContentKeyPolicyWidevineConfiguration; -import com.microsoft.azure.management.mediaservices.v2020_05_01.EncoderNamedPreset; -import com.microsoft.azure.management.mediaservices.v2020_05_01.Job; -import com.microsoft.azure.management.mediaservices.v2020_05_01.JobInputHttp; -import com.microsoft.azure.management.mediaservices.v2020_05_01.JobOutput; -import com.microsoft.azure.management.mediaservices.v2020_05_01.JobOutputAsset; -import com.microsoft.azure.management.mediaservices.v2020_05_01.JobState; -import com.microsoft.azure.management.mediaservices.v2020_05_01.ListPathsResponse; -import com.microsoft.azure.management.mediaservices.v2020_05_01.StreamingEndpoint; -import com.microsoft.azure.management.mediaservices.v2020_05_01.StreamingEndpointResourceState; -import com.microsoft.azure.management.mediaservices.v2020_05_01.StreamingLocator; -import com.microsoft.azure.management.mediaservices.v2020_05_01.StreamingLocatorContentKey; -import com.microsoft.azure.management.mediaservices.v2020_05_01.StreamingLocatorContentKeyType; -import com.microsoft.azure.management.mediaservices.v2020_05_01.StreamingPath; -import com.microsoft.azure.management.mediaservices.v2020_05_01.StreamingPolicyStreamingProtocol; -import com.microsoft.azure.management.mediaservices.v2020_05_01.Transform; -import com.microsoft.azure.management.mediaservices.v2020_05_01.TransformOutput; -import com.microsoft.azure.management.mediaservices.v2020_05_01.implementation.MediaManager; + +import javax.naming.AuthenticationException; +import com.azure.core.credential.TokenCredential; +import com.azure.core.http.policy.HttpLogDetailLevel; +import com.azure.core.http.policy.HttpLogOptions; +import com.azure.core.management.exception.ManagementException; +import com.azure.core.management.profile.AzureProfile; +import com.azure.resourcemanager.mediaservices.models.*; +import com.azure.resourcemanager.mediaservices.MediaServicesManager; +import com.azure.identity.ClientSecretCredentialBuilder; import org.apache.commons.codec.binary.Base64; @@ -68,10 +43,8 @@ import io.jsonwebtoken.SignatureAlgorithm; import io.jsonwebtoken.security.Keys; -import com.microsoft.rest.LogLevel; - public class BasicWidevine { - private static final String ADAPTIVE_STREAMING_TRANSFORM_NAME = "MyTransformWithAdaptiveStreamingPreset"; + private static final String TRANSFORM_NAME = "MyTransform"; private static final String ISSUER = "myIssuer"; private static final String AUDIENCE = "myAudience"; private static final String CONTENT_KEY_POLICY_NAME = "WidevineContentKeyPolicy"; @@ -79,7 +52,7 @@ public class BasicWidevine { private static final String MP4_FILE_NAME = "Ignite-short.mp4"; private static final String CONTENT_KEY_IDENTIFIER_CLAIM = "urn:microsoft:azure:mediaservices:contentkeyidentifier"; private static final String MULTI_DRM_CENC_STREAMING = "Predefined_MultiDrmCencStreaming"; - private static final String DEFAULT_STREAMING_ENDPOINT_NAME = "se"; // Please change this to your Streaming Endpoint name. + private static final String DEFAULT_STREAMING_ENDPOINT_NAME = "default"; private static byte[] TOKEN_SIGNING_KEY; @@ -100,15 +73,21 @@ public static void main(String[] args) { * local configuration file. */ private static void runWidevineTest(ConfigWrapper config) { - // Connect to media services, please see https://docs.microsoft.com/en-us/azure/media-services/latest/configure-connect-java-howto + // Connect to media services, please see + // https://docs.microsoft.com/en-us/azure/media-services/latest/configure-connect-java-howto // for details. - ApplicationTokenCredentials credentials = new ApplicationTokenCredentials(config.getAadClientId(), - config.getAadTenantId(), config.getAadSecret(), AzureEnvironment.AZURE); - credentials.withDefaultSubscriptionId(config.getSubscriptionId()); - - // Get MediaManager, the entry point to Azure Media resource management. - MediaManager manager = MediaManager.configure().withLogLevel(LogLevel.BODY_AND_HEADERS) - .authenticate(credentials, credentials.defaultSubscriptionId()); + TokenCredential credential = new ClientSecretCredentialBuilder() + .clientId(config.getAadClientId()) + .clientSecret(config.getAadSecret()) + .tenantId(config.getAadTenantId()) + .build(); + AzureProfile profile = new AzureProfile(config.getAadTenantId(), config.getSubscriptionId(), + com.azure.core.management.AzureEnvironment.AZURE); + + // MediaServiceManager is the entry point to Azure Media resource management. + MediaServicesManager manager = MediaServicesManager.configure() + .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BODY_AND_HEADERS)) + .authenticate(credential, profile); // Signed in. // Create a unique suffix so that we don't have name collisions if you run the @@ -126,12 +105,27 @@ private static void runWidevineTest(ConfigWrapper config) { try { // Ensure that you have the desired encoding Transform. This is really a one // time setup operation. - Transform transform = getOrCreateTransform(manager, config.getResourceGroup(), config.getAccountName(), - ADAPTIVE_STREAMING_TRANSFORM_NAME); + List outputs = new ArrayList<>(); + outputs.add(new TransformOutput().withPreset( + new BuiltInStandardEncoderPreset().withPresetName(EncoderNamedPreset.CONTENT_AWARE_ENCODING))); - // Output from the encoding Job must be written to an Asset, so let's create one - Asset outputAsset = createOutputAsset(manager, config.getResourceGroup(), config.getAccountName(), - outputAssetName); + // Create the transform. + System.out.println("Creating a transform..."); + Transform transform = manager.transforms() + .define(TRANSFORM_NAME) + .withExistingMediaService(config.getResourceGroup(), config.getAccountName()) + .withOutputs(outputs) + .create(); + System.out.println("Transform created"); + + // Output from the encoding Job must be written to an Asset, so let's create + // one. Note that we are using a unique asset name, there should not be a name + // collision. + System.out.println("Creating an output asset..."); + Asset outputAsset = manager.assets() + .define(outputAssetName) + .withExistingMediaService(config.getResourceGroup(), config.getAccountName()) + .create(); Job job = submitJob(manager, config.getResourceGroup(), config.getAccountName(), transform.name(), outputAsset.name(), jobName); @@ -139,7 +133,8 @@ private static void runWidevineTest(ConfigWrapper config) { long startedTime = System.currentTimeMillis(); try { - // First we will try to process Job events through Event Hub in real-time. If this fails for any reason, + // First we will try to process Job events through Event Hub in real-time. If + // this fails for any reason, // we will fall-back on polling Job status instead. System.out.println("Creating a new host to process events from Event Hub..."); @@ -148,15 +143,18 @@ private static void runWidevineTest(ConfigWrapper config) { config.getStorageAccountName() + ";AccountKey=" + config.getStorageAccountKey() + ";EndpointSuffix=core.windows.net"; - // Cleanup storage container. We will config Event Hub to use the storage container configured in appsettings.json. - // All the blobs in will be deleted. + // Cleanup storage container. We will config Event Hub to use the storage + // container configured in appsettings.json. + // All the blobs in will be + // deleted. BlobServiceAsyncClient client = new BlobServiceClientBuilder() .connectionString(storageConnectionString) .buildAsyncClient(); - BlobContainerAsyncClient container = client.getBlobContainerAsyncClient(config.getStorageContainerName()); + BlobContainerAsyncClient container = client + .getBlobContainerAsyncClient(config.getStorageContainerName()); container.listBlobs().subscribe(blobItem -> { - container.getBlobAsyncClient(blobItem.getName()).delete(); - }); + container.getBlobAsyncClient(blobItem.getName()).delete(); + }); // Create a new host to process events from an Event Hub. Object monitor = new Object(); @@ -195,12 +193,17 @@ private static void runWidevineTest(ConfigWrapper config) { } // Get the latest status of the job. - job = manager.jobs().getAsync(config.getResourceGroup(), config.getAccountName(), transform.name(), jobName).toBlocking().first(); + job = manager.jobs() + .get(config.getResourceGroup(), config.getAccountName(), transform.name(), jobName); } catch (Exception e) { - System.out.println("Warning: Failed to connect to Event Hub, please refer README for Event Hub and storage settings."); - // if Event Grid or Event Hub is not configured, We will fall-back on polling instead. - // Polling is not a recommended best practice for production applications because of the latency it introduces. - // Overuse of this API may trigger throttling. Developers should instead use Event Grid. + System.out.println( + "Warning: Failed to connect to Event Hub, please refer README for Event Hub and storage settings."); + // if Event Grid or Event Hub is not configured, We will fall-back on polling + // instead. + // Polling is not a recommended best practice for production applications + // because of the latency it introduces. + // Overuse of this API may trigger throttling. Developers should instead use + // Event Grid. System.out.println("Failed to start Event Grid monitoring, will use polling job status instead..."); job = waitForJobToFinish(manager, config.getResourceGroup(), config.getAccountName(), transform.name(), jobName); @@ -223,7 +226,7 @@ private static void runWidevineTest(ConfigWrapper config) { config.getAccountName(), CONTENT_KEY_POLICY_NAME); StreamingLocator locator = manager.streamingLocators().define(locatorName) - .withExistingMediaservice(config.getResourceGroup(), config.getAccountName()) + .withExistingMediaService(config.getResourceGroup(), config.getAccountName()) .withAssetName(outputAssetName) .withStreamingPolicyName(MULTI_DRM_CENC_STREAMING) .withDefaultContentKeyPolicyName(policy.name()) @@ -244,26 +247,27 @@ private static void runWidevineTest(ConfigWrapper config) { String token = createToken(ISSUER, AUDIENCE, keyIdentifier, TOKEN_SIGNING_KEY); StreamingEndpoint streamingEndpoint = manager.streamingEndpoints() - .getAsync(config.getResourceGroup(), config.getAccountName(), DEFAULT_STREAMING_ENDPOINT_NAME) - .toBlocking().first(); + .get(config.getResourceGroup(), config.getAccountName(), DEFAULT_STREAMING_ENDPOINT_NAME); if (streamingEndpoint != null) { // Start The Streaming Endpoint if it is not running. if (streamingEndpoint.resourceState() != StreamingEndpointResourceState.RUNNING) { System.out.println("Streaming endpoint was stopped, restarting it..."); - manager.streamingEndpoints().startAsync(config.getResourceGroup(), config.getAccountName(), DEFAULT_STREAMING_ENDPOINT_NAME).await(); + manager.streamingEndpoints().start(config.getResourceGroup(), config.getAccountName(), DEFAULT_STREAMING_ENDPOINT_NAME); // We started the endpoint, we should stop it in cleanup. stopEndpoint = true; } - String dashPath = getDASHStreamingUrl(manager, config.getResourceGroup(), config.getAccountName(), locator.name(), streamingEndpoint); - + String dashPath = getDASHStreamingUrl(manager, config.getResourceGroup(), config.getAccountName(), + locator.name(), streamingEndpoint); System.out.println(); - System.out.println("Copy and paste the following URL in your browser to play back the file in the Azure Media Player."); + System.out.println( + "Copy and paste the following URL in your browser to play back the file in the Azure Media Player."); System.out.println("You can use Chrome/Firefox for Widevine."); System.out.println(); - System.out.println("https://ampdemo.azureedge.net/?url=" + dashPath + "&widevine=true&token=Bearer%3D" + token); + System.out.println("https://ampdemo.azureedge.net/?url=" + dashPath + + "&widevine=true&token=Bearer%3D" + token); System.out.println(); } else { System.out.println("Could not find streaming endpoint: " + DEFAULT_STREAMING_ENDPOINT_NAME); @@ -279,10 +283,6 @@ private static void runWidevineTest(ConfigWrapper config) { if (cause instanceof AuthenticationException) { System.out.println("ERROR: Authentication error, please check your account settings in appsettings.json."); break; - } else if (cause instanceof ApiErrorException) { - ApiErrorException apiException = (ApiErrorException) cause; - System.out.println("ERROR: " + apiException.body().error().message()); - break; } cause = cause.getCause(); } @@ -292,8 +292,10 @@ private static void runWidevineTest(ConfigWrapper config) { } finally { System.out.println("Cleaning up..."); - cleanup(manager, config.getResourceGroup(), config.getAccountName(), ADAPTIVE_STREAMING_TRANSFORM_NAME, jobName, - outputAssetName, locatorName, CONTENT_KEY_POLICY_NAME, stopEndpoint, DEFAULT_STREAMING_ENDPOINT_NAME); + cleanup(manager, config.getResourceGroup(), config.getAccountName(), TRANSFORM_NAME, + jobName, + outputAssetName, locatorName, CONTENT_KEY_POLICY_NAME, stopEndpoint, + DEFAULT_STREAMING_ENDPOINT_NAME); if (scanner != null) { scanner.close(); @@ -309,45 +311,6 @@ private static void runWidevineTest(ConfigWrapper config) { } } - /** - * If the specified transform exists, get that transform. If the it does not - * exist, creates a new transform with the specified output. In this case, the - * output is set to encode a video using one of the built-in encoding presets. - * - * @param manager The entry point of Azure Media resource management. - * @param resourceGroup The name of the resource group within the Azure subscription. - * @param accountName The Media Services account name. - * @param transformName The name of the transform. - * @return The transform found or created. - */ - private static Transform getOrCreateTransform(MediaManager manager, String resourceGroup, String accountName, - String transformName) { - Transform transform; - try { - // Does a Transform already exist with the desired name? Assume that an existing - // Transform with the desired name. - transform = manager.transforms().getAsync(resourceGroup, accountName, transformName).toBlocking().first(); - } catch (NoSuchElementException e) { - transform = null; // Media Services V3 throws an exception when not found, this will be changed to return null. - } - - if (transform == null) { - // Start by defining the desired outputs. - BuiltInStandardEncoderPreset preset = new BuiltInStandardEncoderPreset() - .withPresetName(EncoderNamedPreset.ADAPTIVE_STREAMING); - TransformOutput transformOutput = new TransformOutput().withPreset(preset); - List outputs = new ArrayList(); - outputs.add(transformOutput); - - // Create the Transform with the output defined above. - System.out.println("Creating a transform..."); - transform = manager.transforms().define(transformName).withExistingMediaservice(resourceGroup, accountName) - .withOutputs(outputs).create(); - } - - return transform; - } - /** * Creates an output asset. The output from the encoding Job must be written to * an Asset. @@ -358,11 +321,11 @@ private static Transform getOrCreateTransform(MediaManager manager, String resou * @param assetName The output asset name. * @return The output asset created. */ - private static Asset createOutputAsset(MediaManager manager, String resourceGroupName, String accountName, + private static Asset createOutputAsset(MediaServicesManager manager, String resourceGroupName, String accountName, String assetName) { // We are assuming the asset name is unique. System.out.println("Creating an output asset..."); - Asset outputAsset = manager.assets().define(assetName).withExistingMediaservice(resourceGroupName, accountName) + Asset outputAsset = manager.assets().define(assetName).withExistingMediaService(resourceGroupName, accountName) .create(); return outputAsset; @@ -372,8 +335,10 @@ private static Asset createOutputAsset(MediaManager manager, String resourceGrou * Submits a request to Media Services to apply the specified Transform to a * given input video. * - * @param manager This is the entry point of Azure Media resource management. - * @param resourceGroupName The name of the resource group within the Azure subscription. + * @param manager This is the entry point of Azure Media resource + * management. + * @param resourceGroupName The name of the resource group within the Azure + * subscription. * @param accountName The Media Services account name. * @param transformName The name of the transform. * @param outputAssetName The (unique) name of the output asset that will @@ -381,9 +346,10 @@ private static Asset createOutputAsset(MediaManager manager, String resourceGrou * @param jobName The (unique) name of the job. * @return The job created. */ - private static Job submitJob(MediaManager manager, String resourceGroupName, String accountName, + private static Job submitJob(MediaServicesManager manager, String resourceGroupName, String accountName, String transformName, String outputAssetName, String jobName) { - // This example shows how to encode from any HTTPs source URL - a new feature of the v3 API. + // This example shows how to encode from any HTTPs source URL - a new feature of + // the v3 API. // Change the URL to any accessible HTTPs URL or SAS URL from Azure. List files = new ArrayList<>(); files.add(MP4_FILE_NAME); @@ -396,7 +362,8 @@ private static Job submitJob(MediaManager manager, String resourceGroupName, Str // In this example, we are assuming that the job name is unique. // If you already have a job with the desired name, use the Jobs.Get method - // to get the existing job. In Media Services v3, the Get method on entities returns null + // to get the existing job. In Media Services v3, the Get method on entities + // returns null // if the entity doesn't exist (a case-insensitive check on the name). System.out.println("Creating a job..."); Job job = manager.jobs().define(jobName).withExistingTransform(resourceGroupName, accountName, transformName) @@ -408,14 +375,16 @@ private static Job submitJob(MediaManager manager, String resourceGroupName, Str /** * Polls Media Services for the status of the Job. * - * @param manager This is the entry point of Azure Media resource management. - * @param resourceGroup The name of the resource group within the Azure subscription. + * @param manager This is the entry point of Azure Media resource + * management. + * @param resourceGroup The name of the resource group within the Azure + * subscription. * @param accountName The Media Services account name. * @param transformName The name of the transform. * @param jobName The name of the job you submitted. * @return The job. */ - private static Job waitForJobToFinish(MediaManager manager, String resourceGroup, String accountName, + private static Job waitForJobToFinish(MediaServicesManager manager, String resourceGroup, String accountName, String transformName, String jobName) { final int SLEEP_INTERVAL = 60 * 1000; @@ -423,7 +392,7 @@ private static Job waitForJobToFinish(MediaManager manager, String resourceGroup boolean exit = false; do { - job = manager.jobs().getAsync(resourceGroup, accountName, transformName, jobName).toBlocking().first(); + job = manager.jobs().get(resourceGroup, accountName, transformName, jobName); if (job.state() == JobState.FINISHED || job.state() == JobState.ERROR || job.state() == JobState.CANCELED) { exit = true; @@ -451,24 +420,26 @@ private static Job waitForJobToFinish(MediaManager manager, String resourceGroup } /** - * Create the content key policy that configures how the content key is delivered - * to end clients via the Key Delivery component of Azure Media Services. + * Create the content key policy that configures how the content key is + * delivered to end clients via the Key Delivery component of + * Azure Media Services. * - * @param manager The entry point of Azure Media resource management. - * @param resourceGroup The name of the resource group within the Azure subscription. + * @param manager The entry point of Azure Media resource + * management. + * @param resourceGroup The name of the resource group within the Azure + * subscription. * @param accountName The Media Services account name. * @param contentKeyPolicyName The name of the content key policy resource. * @return The content key policy. * @throws JsonProcessingException */ - private static ContentKeyPolicy ensureContentKeyPolicyExists(MediaManager manager, String resourceGroup, - String accountName, String contentKeyPolicyName) throws JsonProcessingException { + private static ContentKeyPolicy ensureContentKeyPolicyExists(MediaServicesManager manager, String resourceGroup, + String accountName, String contentKeyPolicyName) throws JsonProcessingException { ContentKeyPolicy policy; try { // Get the policy if exists. - policy = manager.contentKeyPolicies().getAsync(resourceGroup, accountName, contentKeyPolicyName) - .toBlocking().first(); - } catch (NoSuchElementException e) { + policy = manager.contentKeyPolicies().get(resourceGroup, accountName, contentKeyPolicyName); + } catch (ManagementException e) { policy = null; } @@ -520,11 +491,11 @@ private static ContentKeyPolicy ensureContentKeyPolicyExists(MediaManager manage // Content Key Policy does not exist, create one. policy = manager.contentKeyPolicies().define(contentKeyPolicyName) - .withExistingMediaservice(resourceGroup, accountName).withOptions(options).create(); + .withExistingMediaService(resourceGroup, accountName).withOptions(options).create(); } else { // Get the signing key from the existing policy. ContentKeyPolicyProperties policyProperties = manager.contentKeyPolicies() - .getPolicyPropertiesWithSecretsAsync(resourceGroup, accountName, contentKeyPolicyName).toBlocking().first(); + .getPolicyPropertiesWithSecrets(resourceGroup, accountName, contentKeyPolicyName); ContentKeyPolicyRestriction restriction = policyProperties.options().get(0).restriction(); if (restriction != null && restriction instanceof ContentKeyPolicyTokenRestriction) { ContentKeyPolicyTokenRestriction contentKeyPolicyTokenRestriction = (ContentKeyPolicyTokenRestriction) restriction; @@ -590,7 +561,7 @@ private static ContentKeyPolicyWidevineConfiguration configureWidevineLicenseTem * @throws JwtException */ private static String createToken(String issuer, String audience, String keyIdentifier, - byte[] tokenVerificationKey) throws JwtException { + byte[] tokenVerificationKey) throws JwtException { String jws = null; SecretKey key = Keys.hmacShaKeyFor(tokenVerificationKey); @@ -600,7 +571,8 @@ private static String createToken(String issuer, String audience, String keyIden .setAudience(audience) .claim(CONTENT_KEY_IDENTIFIER_CLAIM, keyIdentifier) .setNotBefore(Date.from(LocalDateTime.now().minusMinutes(5).atZone(ZoneId.systemDefault()).toInstant())) - .setExpiration(Date.from(LocalDateTime.now().plusMinutes(60).atZone(ZoneId.systemDefault()).toInstant())) + .setExpiration( + Date.from(LocalDateTime.now().plusMinutes(60).atZone(ZoneId.systemDefault()).toInstant())) .signWith(key, SignatureAlgorithm.HS256); jws = builder.compact(); @@ -613,23 +585,23 @@ private static String createToken(String issuer, String audience, String keyIden * Then, builds the streaming URLs. * * @param manager The entry point of Azure Media resource management - * @param resourceGroup The name of the resource group within the Azure subscription + * @param resourceGroup The name of the resource group within the Azure + * subscription * @param accountName The Media Services account name * @param locatorName The name of the StreamingLocator that was created * @return The DASH streaming url. */ - private static String getDASHStreamingUrl(MediaManager manager, String resourceGroup, String accountName, + private static String getDASHStreamingUrl(MediaServicesManager manager, String resourceGroup, String accountName, String locatorName, StreamingEndpoint streamingEndpoint) { String dashPath = ""; ListPathsResponse paths = manager.streamingLocators() - .listPathsAsync(resourceGroup, accountName, locatorName) - .toBlocking().first(); + .listPaths(resourceGroup, accountName, locatorName); for (StreamingPath path : paths.streamingPaths()) { if (path.paths().size() > 0) { StringBuilder uriBuilder = new StringBuilder(); - uriBuilder.append("https://").append(streamingEndpoint.hostName()); + uriBuilder.append("https://").append(streamingEndpoint.hostname()); // Look for just the DASH path and generate a URL for the Azure Media Player to playback the content with the AES token to decrypt. // Note that the JWT token is set to expire in 1 hour. @@ -646,7 +618,8 @@ private static String getDASHStreamingUrl(MediaManager manager, String resourceG /** * Deletes the jobs and assets that were created. * Generally, you should clean up everything except objects - * that you are planning to reuse (typically, you will reuse Transforms, and you will persist StreamingLocators). + * that you are planning to reuse (typically, you will reuse Transforms, and you + * will persist StreamingLocators). * * @param manager The entry point of Azure Media resource management. * @param resourceGroup The name of the resource group within the Azure subscription. @@ -659,21 +632,24 @@ private static String getDASHStreamingUrl(MediaManager manager, String resourceG * @param stopEndpoint Stop endpoint if true, otherwise keep endpoint running. * @param streamingEndpointName The endpoint name. */ - public static void cleanup(MediaManager manager, String resourceGroup, String accountName, String transformName, String jobName, - String assetName, String locatorName, String contentKeyPolicyName, boolean stopEndpoint, String streamingEndpointName) { + public static void cleanup(MediaServicesManager manager, String resourceGroup, String accountName, + String transformName, + String jobName, + String assetName, String locatorName, String contentKeyPolicyName, boolean stopEndpoint, + String streamingEndpointName) { if (manager == null) { return; } - manager.jobs().deleteAsync(resourceGroup, accountName, transformName, jobName).await(); - manager.assets().deleteAsync(resourceGroup, accountName, assetName).await(); + manager.jobs().delete(resourceGroup, accountName, transformName, jobName); + manager.assets().delete(resourceGroup, accountName, assetName); - manager.streamingLocators().deleteAsync(resourceGroup, accountName, locatorName).await(); - manager.contentKeyPolicies().deleteAsync(resourceGroup, accountName, contentKeyPolicyName).await(); + manager.streamingLocators().delete(resourceGroup, accountName, locatorName); + manager.contentKeyPolicies().delete(resourceGroup, accountName, contentKeyPolicyName); if (stopEndpoint) { // Because we started the endpoint, we'll stop it. - manager.streamingEndpoints().stopAsync(resourceGroup, accountName, streamingEndpointName).await(); + manager.streamingEndpoints().stop(resourceGroup, accountName, streamingEndpointName); } else { // We will keep the endpoint running because it was not started by this sample. // Please note, There are costs to keep it running.