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

时间:2015-10-01 16:07:01

标签: c# azure azure-media-services

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

1 个答案:

答案 0 :(得分:0)

创建定位器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;
        }