如何使用来自 Azure 媒体服务 CDN 的自定义域创建流定位器? [关闭]

问题描述 投票:0回答:0

目前,我们正在使用 Azure 媒体服务进行流式传输。 我们只有一个启用了 CDN 的标准流媒体端点(标准 Verizon)。

自定义域已添加到 CDN 以使用我们当前的域。

流定位器是使用 .NET SDK 创建的,因此不会通过 Azure 门户创建定位器。

这就是我从 AMS 获取 Streaming Endpoint 的方式(观察:客户端是

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);
}

这里是 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);
}

这就是我为每个协议(Dash、Hls 和 Smooth)创建流媒体 URL 的方式:

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());
}

在调试方面,这是我从

streamingEndpoint.HostName

获得的 URL

要使用我添加到 CDN 的自定义域,我使用直接添加到 uriBuilder:

UriBuilder uriBuilder = new()
{
    Scheme = "https",
    Host = "my-custom-domain-for-stream.com",
    Path = streamingPath.Paths.FirstOrDefault() ?? String.Empty
};

但是,在 Azure 门户上,定位器是使用默认主机名创建的:

我的问题是:如何创建使用添加到 CDN 的新自定义域的流定位器?还是在 ASM 上使用自定义域的正确方法?

如果我用我的自定义域替换 Streaming Endpoint 域,它工作得很好。

我可以在 Streaming Enpoint 上找到

customHostNames
的用法,但这仅在此处指定的 CDN 被禁用时才有效: https://learn.microsoft.com/en-us/azure/media-services/latest/stream-streaming-endpoint-concept

据我了解带有 CDN + 流定位器的流媒体端点,似乎流媒体端点不知道 CDN 配置(自定义域),它必须在代码本身上解决。

我的结论是:最后,流定位器将使用默认主机名创建,但我们可以自由使用添加到 CDN 的任何自定义域。

.net azure azure-media-services
© www.soinside.com 2019 - 2024. All rights reserved.