You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure Media Service自定义Streaming Policy启用FairPlay离线功能报错如何处理

问题根因

你错误地将本地变量名作为已存在的Streaming Policy名称传入API,nameof(objStreamingPolicyInput)只会返回本地变量的字符串标识objStreamingPolicyInput,Azure媒体服务侧并未存在对应名称的策略资源,因此触发BadRequest错误。

正确实现逻辑

你需要先在Azure媒体服务账户中创建自定义Streaming Policy资源,再将该策略的名称传入Streaming Locator的创建参数,不能直接用本地配置对象的变量名。

修正后的代码示例
private static async Task<StreamingLocator> CreateStreamingLocatorAsync(
    IAzureMediaServicesClient client,
    string resourceGroup,
    string accountName,
    string assetName,
    string locatorName,
    string contentPolicyName)
{
    // 自定义策略名称,全局唯一即可
    string customFairPlayPolicyName = "FairPlayOfflineCustomPolicy";

    // 先判断策略是否已存在,避免重复创建
    var existingPolicy = await client.StreamingPolicies.GetAsync(resourceGroup, accountName, customFairPlayPolicyName);
    if (existingPolicy == null)
    {
        CommonEncryptionCbcs cbcsConfig = new CommonEncryptionCbcs()
        {
            Drm = new CbcsDrmConfiguration()
            {
                FairPlay = new StreamingPolicyFairPlayConfiguration()
                {
                    AllowPersistentLicense = true // 启用离线模式
                }
            },
            EnabledProtocols = new EnabledProtocols()
            {
                Hls = true,
                Dash = true 
            },
            ContentKeys = new StreamingPolicyContentKeys()
            {
                DefaultKey = new DefaultKey()
                {
                    Label = "CBCS_DefaultKeyLabel"
                }
            }
        };

        // 创建自定义Streaming Policy资源
        await client.StreamingPolicies.CreateAsync(resourceGroup, accountName, customFairPlayPolicyName, new StreamingPolicy
        {
            CommonEncryptionCbcs = cbcsConfig
        });
    }

    // 创建Streaming Locator时传入已创建的自定义策略名称
    StreamingLocator locator = await client.StreamingLocators.CreateAsync(
        resourceGroup,
        accountName,
        locatorName,
        new StreamingLocator
        {
            AssetName = assetName,
            StreamingPolicyName = customFairPlayPolicyName,
            DefaultContentKeyPolicyName = contentPolicyName
        });

    return locator;
}
注意事项
  • 自定义Streaming Policy创建后无法修改配置,如需调整参数需要新建新的策略,使用不同的名称
  • 请提前确认你的Content Key Policy中已经配置了FairPlay所需的公钥证书、应用密钥(ASK)、license交付URL等必填参数
  • 不需要离线播放的场景可以直接使用预定义策略Predefined_MultiDrmStreaming,无需自定义策略

内容的提问来源于stack exchange,提问作者ron94

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.02 08:24:02