Azure媒体服务定位符

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

基于上一个问题,我仍然没有定位器。

Previous Locator Question

如果我创建一个持续1小时的定位器,当它过期时,我如何知道当前的定位器已过期?

我相信我将需要存储assetId,以便以后可以请求它。

  • 我也将到期日存储在我的身边吗?
  • 或者是当我请求它时,我得到一个无效的http状态,并以此为基础创建了一个新的定位器?
  • 所有过期的定位器都会发生什么,我读到您只有5个,所以我需要清理过期的定位器吗?

认为主要问题是,当旧的定位器过期时如何创建新的定位器,但是我怎么知道旧的定位器过期了?

下面的代码是我获取定位器所需要的,但是无法找出定位器是否已过期。

        // Try and get an access policy and reuse it if found
        var tempPolicyId = from a in _context.AccessPolicies
            where a.Name == PolicyName
            select a;

        IAccessPolicy accessPolicy = null;

        if (tempPolicyId.Count() < 1)
        {
            accessPolicy = _context.AccessPolicies.Create(
                PolicyName,
                TimeSpan.FromMinutes(5), // expire in 5 minutes
                AccessPermissions.List | AccessPermissions.Read);
        }
        else
        {
            accessPolicy = tempPolicyId.FirstOrDefault();
        }
        _context.Locators.CreateLocator(
            LocatorType.OnDemandOrigin,
            asset,
            accessPolicy,
            DateTime.UtcNow.AddMinutes(-5));

        _context.Locators.CreateLocator(
            LocatorType.Sas,
            asset,
            accessPolicy,
            DateTime.UtcNow.AddMinutes(-5));
    }

非常感谢您的帮助,谢谢

c# azure azure-media-services
1个回答
1
投票

我强烈建议最少存储资产ID。从中您可以找到有关资产的几乎所有信息。如果您使用的是建议的寿命短的定位器,则存储到期日期并不坏。我认为这是短暂的1小时。通常,我会创建10或100年的定位器,然后通过DRM管理访问。

要知道定位器何时到期,可以调用ILocator.ExpirationDateTime .ToUniversalTime()来查找定位器将要终止或终止的日期/时间。

当定位器过期时,如果您处于5个定位器限制之内,则需要先删除它,然后才能添加新的定位器。您也可以调用ILocator.Update(DateTime newExpiryTime)

© www.soinside.com 2019 - 2024. All rights reserved.