Azure媒体服务共享访问策略限制 [英] Azure Media Services Shared Access Policy limitations

查看:62
本文介绍了Azure媒体服务共享访问策略限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建有时间限制的URL,以平滑流存储在Azure媒体服务中的媒体.

I'm trying to create time-limited URL's for smooth streaming of media stored in Azure Media Services.

我正在使用此处提供的代码. Windows Azure流畅串流示例

I am working against the code supplied here. Windows Azure Smooth Streaming example

我将视频文件上传到新资产.我使用带有预设"H264自适应比特率MP4设置720p"的Azure媒体服务编码对该视频文件进行编码.然后,使用生成的编码资产,尝试通过创建访问策略和定位器来创建流URL,该定位器用于生成用于流的URL.

I upload a video file to a new Asset. I encode that video file using Azure Media Service encoding with the preset "H264 Adaptive Bitrate MP4 Set 720p". With the resulting encoded asset, I then attempt to create a streaming URL by creating an Access Policy and then a Locator, which I use to generate the URL used for streaming.

这是代码:

string urlForClientStreaming = "";

IAssetFile manifestFile = (from f in Asset.AssetFiles
                   where f.Name.EndsWith(".ism")
                   select f).FirstOrDefault();

if (manifestFile != null)
{ 
    // Create a 1 hour readonly access policy. 
    IAccessPolicy policy = _mediaContext.AccessPolicies.Create("Streaming policy",   TimeSpan.FromHours(1), AccessPermissions.Read);

    // Create a locator to the streaming content on an origin. 
    ILocator originLocator =     _mediaContext.Locators.CreateLocator(LocatorType.OnDemandOrigin, Asset,    policy, DateTime.UtcNow.AddMinutes(-5));

    urlForClientStreaming = originLocator.Path + manifestFile.Name + "/manifest";

    if (contentType == MediaContentType.HLS)
    urlForClientStreaming = String.Format("{0}{1}", urlForClientStreaming, "(format=m3u8-aapl)");
}

return urlForClientStreaming;

这很好.直到第6次,您才对同一资产执行该代码.然后,您会收到此错误:

This works great. Until the 6th time you execute that code against the same Asset. Then you receive this error:

服务器不支持在单个容器上设置超过5个共享访问策略标识符."

"Server does not support setting more than 5 shared access policy identifiers on a single container."

那么,那很好.我不需要每次都创建一个新的AccessPolicy,可以重用以前创建的AccessPolicy,并使用相同的策略来构建Locator.但是,即使那样,我仍然在单个容器上收到有关5个共享访问策略的错误.

So, that's fine. I don't need to create a new AccessPolicy everytime, I can reuse the one I've created previously, build a Locator using that same policy. However, even then, I get the error about 5 shared access policies on a single container.

这是使用先前使用的相同AccessPolicy创建定位器的新代码:

Here is the new code that creates the locator with the same AccessPolicy used previously:

string urlForClientStreaming = "";

IAssetFile manifestFile = (from f in Asset.AssetFiles
                   where f.Name.EndsWith(".ism")
                   select f).FirstOrDefault();

if (manifestFile != null)
{ 
    // Create a 1 hour readonly access policy
    IAccessPolicy accessPolicy = null;
    accessPolicy =
      (from p in _mediaContext.AccessPolicies where p.Name == "myaccesspolicy" select p).FirstOrDefault();

     if (accessPolicy == null)
     {
         accessPolicy = _mediaContext.AccessPolicies.Create("myaccesspolicy", TimeSpan.FromHours(1), AccessPermissions.Read);
     }

    // Create a locator to the streaming content on an origin. 
    ILocator originLocator =     _mediaContext.Locators.CreateLocator(LocatorType.OnDemandOrigin, Asset,    policy, DateTime.UtcNow.AddMinutes(-5));

    urlForClientStreaming = originLocator.Path + manifestFile.Name + "/manifest";

    if (contentType == MediaContentType.HLS)
    urlForClientStreaming = String.Format("{0}{1}", urlForClientStreaming, "(format=m3u8-aapl)");
}

return urlForClientStreaming;

我不明白为什么要说我创建了5个共享访问策略.在第二段代码中,我只创建了一个访问策略.我可以通过查看 _mediaContext.AccessPolicies 的内容来验证是否只有一个AccessPolicy,该列表中始终只有一个访问策略.

I don't understand why it's saying I've created 5 shared access policies. In the case of the second block of code, I only ever create one access policy. I can verify there is only ever one AccessPolicy by viewing the content of _mediaContext.AccessPolicies, there is always just one access policy in that list.

在某个时候,这可能会使许多用户请求访问同一资产.根据我们客户的要求,提供给这些客户的URL必须受时间限制.

At some point this will likely have many users requesting access to the same Asset. The URL's provided to these clients need to be time limited as per our clients requirements.

这不是创建用于平稳流式传输资产的URL的适当方法吗?

Is this not the appropriate means to create a URL for smooth streaming of an asset?

推荐答案

现在,借助Azure Media Services内容保护功能,您可以使用AES或PlayReady对媒体文件进行加密,并生成一个长期存在的定位器.同时,您为内容密钥设置了令牌授权策略,令牌持续时间可以设置为较短的时间(玩家可以检索内容密钥).这样,您可以控制内容访问.有关更多信息,请参阅我的博客:

Now with Azure Media Services content protection feature, you could encrypt your media file with either AES or PlayReady, generate a long-lived locator. At the same time, you set Token-Authorization policy for the content key, the token duration could be set to a short-period of time (enough for the player to retrieve the content key). This way you could control your content access. For more information, you could refer to my blog: http://azure.microsoft.com/blog/2014/09/10/announcing-public-availability-of-azure-media-services-content-protection-services/

这篇关于Azure媒体服务共享访问策略限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆