Currently, we are using Azure Media Services for streaming purposes. We have only one standard streaming endpoint with a CDN enabled (Standard Verizon).
A custom domain has been added to the CDN to use our current domain.
The streaming locator is created using the .NET SDK, so no locator is created through the Azure Portal.
This is how I get the Streaming Endpoint from AMS (Obs.: client is an instance of IAzureMediaServicesClient):
StreamingEndpoint streamingEndpoint = await client.StreamingEndpoints.GetAsync(
config.ResourceGroup,
config.AccountName,
config.DefaultStreamingEndpointName, // default
cancellationToken);
if (streamingEndpoint.ResourceState != StreamingEndpointResourceState.Running)
{
await client.StreamingEndpoints.StartAsync(
config.ResourceGroup,
config.AccountName,
config.DefaultStreamingEndpointName, // default
cancellationToken);
}
Here is the creation of the Streaming Locator:
try
{
StreamingLocator locator = await client.StreamingLocators.GetAsync(
config.ResourceGroup,
config.AccountName,
streamingLocatorName,
cancellationToken);
}
catch (ErrorResponseException exception) when (exception.Response.StatusCode == HttpStatusCode.NotFound)
{
StreamingLocator locator = await client.StreamingLocators.CreateAsync(
config.ResourceGroup,
config.AccountName,
streamingLocatorName,
new StreamingLocator
{
AssetName = videoStreaming.EncodeId,
StreamingPolicyName = PredefinedStreamingPolicy.ClearKey,
DefaultContentKeyPolicyName = contentKeyPolicy.Name
},
cancellationToken);
}
And this is how I create the streaming urls for each protocol (Dash, Hls and Smooth):
ListPathsResponse paths = await client.StreamingLocators.ListPathsAsync(
config.ResourceGroup,
config.AccountName,
streamingLocatorName,
cancellationToken);
List<string> streamingUrls = new ();
foreach (StreamingPath path in paths.StreamingPaths)
{
UriBuilder uriBuilder = new()
{
Scheme = "https",
Host = streamingEndpoint.HostName,
Path = streamingPath.Paths.FirstOrDefault() ?? String.Empty
};
streamingUrls.Add(uriBuilder.ToString());
}
On the debug side, this is the URL that I got from streamingEndpoint.HostName
To use the custom domain that I have added to the CDN, I am using adding directly to the uriBuilder:
UriBuilder uriBuilder = new()
{
Scheme = "https",
Host = "my-custom-domain-for-stream.com",
Path = streamingPath.Paths.FirstOrDefault() ?? String.Empty
};
However, on the Azure Portal, the Locator was created using the default host name:
My question is: how can I create a streaming locator that uses the new custom domain added to the CDN? Or is it the proper way to use custom domains on ASM?
If I replace the Streaming Endpoint domain with my custom domain, it works just fine.
I could find the usage of customHostNames on the Streaming Enpoint, but that is only valid when a CDN is disabled as specified here:
https://learn.microsoft.com/en-us/azure/media-services/latest/stream-streaming-endpoint-concept
As far as I read about the Streaming Endpoint with CDN + the Streaming Locator, it seems that the Streaming Endpoint is not aware of the CDN configuration (custom domains) and it must be addressed on the code itself.
My conclusion is: In the end, the streaming locator will be created with the default Host Name but we are free to use any custom domain added to the CDN.



After a few weeks looking for the solution, I figure it out that CDN for AMS endpoint works on the same way as CDN for Blob Storage using SAS Token.
Basically, AMS is not "aware" that a custom domain exists for a streaming endpoint. In general, you have to replace the domain on the endpoint using your custom domain.
The way to do for SAS Token can be checked on the links below:
The code below (that is on the question as well) is the way to go using AMS:
Unfortunately, Azure Media Services will be retired on June the 30th 2024.