繁体   English   中英

如何以编程方式更改Azure媒体服务定位器的读取策略?

[英]How to programmatically change the read policy for azure media service locator?

在将定位器添加到我上传到azure媒体服务的几个文件中时,我错误地在mp4文件上添加并设置了错误的到期时间。 我还将每个上载文件的信息存储在数据库中,包括指向定位器的链接。 有什么方法可以为我当前存储在媒体服务中的每个文件的定位器上的过期时间重置,并能够为每个文件检索新的定位器?

创建定位器API可以获取locatorID作为参数。 您需要获取现有的定位器并将其删除,然后使用相同的GUID创建,以便您可以更新到期日期并保留相同的定位器(URL)。

这是一个示例,它将存储现有的定位器详细信息并重新创建。

private static ILocator RecreateLocator(ILocator locator, CloudMediaContext mediaContext)
        {
            // Save properties of existing locator.
            var asset = locator.Asset;
            var accessPolicy = locator.AccessPolicy;
            var locatorId = locator.Id;
            var startDate = locator.StartTime;
            var locatorType = locator.Type;
            var locatorName = locator.Name;

            // Delete old locator.
            locator.Delete();

            if (locator.ExpirationDateTime <= DateTime.UtcNow)
            {
                throw new Exception(String.Format(
                    "Cannot recreate locator Id={0} because its locator expiration time is in the past", 
                    locator.Id));
            }

            // Create new locator using saved properties.
            var newLocator = mediaContext.Locators.CreateLocator(
                locatorId,
                locatorType,
                asset,
                accessPolicy,
                startDate,
                locatorName);

            Trace.TraceInformation("Locator created. Name={0}, path={1}", newLocator.Name, newLocator.Path);

            return newLocator;
        }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM