Home > Software design >  Azure Media services, create locator fails using .NET library
Azure Media services, create locator fails using .NET library

Time:07-19

An old V2 Media services account used to be working happily with the given code:

var contentKeys = new List<StreamingLocatorContentKey>
{
    new StreamingLocatorContentKey(
        contentKeyId,
        StreamingLocatorContentKeyType.CommonEncryptionCenc,
        "cencKeyDefault",
        Convert.ToBase64String(contentKeyValue))
};

return await mClient.StreamingLocators.CreateAsync(
    mResourceGroupName, mAccountName,
    locatorName,
    new StreamingLocator(assetName, PredefinedStreamingPolicy.MultiDrmCencStreaming,
                         defaultContentKeyPolicyName: "KeyPolicy",
                         contentKeys: contentKeys));

Here locatorName is $"Locator-{contentKeyId:N}". This code created a locator with the predefined key. Now the call throws a BadRequest exception with no additional details.

  1. Creating a new account, V2 or V3, yields the same result.

  2. Removing contentKeys: contentKeys makes the code work again - but I need to pass on the key value, so no good for me. Still, this indicates that there is something wrong with the key part of the request.

  3. Using the following POST request works fine:

     POST https://management.azure.com/subscriptions/{{subscriptionId}}/resourceGroups/{{resourceGroup}}/providers/Microsoft.Media/mediaServices/{{msName}}/streamingLocators/Locator-A1?api-version=2021-11-01
    
     {
         "properties": {
             "assetName": "Video-A1",
             "streamingPolicyName": "Predefined_MultiDrmCencStreaming",
             "defaultContentKeyPolicyName": "KeyPolicy",
             "contentKeys": [
             {
                 "labelReferenceInStreamingPolicy": "cencKeyDefault",
                 "id": "60000000-0000-0000-0000-000000000001",
                 "value": "1UqLohAfWsEGkULYxHjYZg=="
             }]
         }
     }
    

So it's not Azure per se, it must be the way the request is generated, or the way I use the API.

Environment

  • Project: .NET 6
  • Microsoft.Azure.Common: 2.2.1
  • Microsoft.Azure.Management.Media: 6.0.0
  • Microsoft.Azure.Storage.Blob: 11.2.3
  • Microsoft.Rest.ClientRuntime.Azure.Authentication: 2.4.1

So, what could have become wrong in my code? And how can I debug the Azure calls to get the error message, not just the BadRequest code?

PS

The documentation here erroneously mentions cencDefaultKey, that does not work - it must be cencKeyDefault.

PPS

Apparently, when trying to insert a table, StackOverflow believes it is a badly formatted code - on submittin, preview works fine. Took me a few attempts to identify the culprit.

CodePudding user response:

It will be easiest to debug the issue if you file a support ticket from Azure Portal with your media account information and request information.

Since you mention that getting rid of the contentkeys parameter fixes the BadRequest, it is possible that there is a mismatch between the number of content keys specified in the Streaming Policy and the number of keys that you are specifying when creating the locator. If you do not specify any key, the server auto-generates all the required keys.

Additionally, BadRequest responses should always contain useful information. You can capture that by either routing your requests through an app like Fiddler or using a code snippet like below:

try
{
    await Client.StreamingLocators.CreateAsync(ResourceGroup, MediaAccount, locator.Name, locator);
}
catch (ErrorResponseException ex)
{
    Console.WriteLine(ex.Response.Content);
}
  • Related