简体   繁体   中英

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

In adding the locators to several files I uploaded to azure media service, I mistakenly, added and set the wrong expiration time on the mp4 files. I am also storing the information for each uploaded file in the database, including the links to the locator. Is there a way I can reset the expiration time on the locators for each file I currently have stored in media services and be able to retrieve the new locators for each file?

Create locator API can get locatorID as a parameter. You need to get existing locator and delete it and then create with the same GUID so you can update the expire date and also keep the same locator(URL).

Here is a sample which will store existing locator details and recreate.

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;
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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