Azure媒体服务定位器 [英] Azure Media Services Locator

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

问题描述

我正在尝试通过c#代码使用Azure媒体服务,在大多数示例中,我可以上传资产,发布资产,然后找到定位器以将其拉回.

I am trying to use azure media services, using c# code, for the most part using the examples I can upload an asset, publish it and then get a locator to pull it back down.

我有点困惑如何生成新的定位器,例如如果旧的过期了?

I am a bit confused how I can generate a new locator e.g. if the old one expires?

例如,如果我现在在上传和编码时创建一个定位器,则可以通过针对CloudMediaContext对象定义此URL来获取URL.

For example If I create a locator now at the time of uploading and encoding, I can get a url by defining this against the CloudMediaContext object.

_context.Locators.Create(
    LocatorType.OnDemandOrigin,
    asset,
    AccessPermissions.Read,
    TimeSpan.FromDays(30));

_context.Locators.Create(
    LocatorType.Sas,
    asset,
    AccessPermissions.Read,
    TimeSpan.FromDays(30));

该网址将在30天后过期,我现在如何获得一个新的网址?

After 30 days the url will expire, how can I get a new one at this time?

非常感谢您提供的帮助:)

Many thanks for any help you can give :)

推荐答案

您似乎正在使用Media Services API的v2版本.定位器过期后,可以通过以下方式创建一个新的定位器:首先定位要向其添加定位器的资产,然后为该资产创建定位器.这是一个示例:

It looks like you're using the v2 version of the Media Services API. After a locator expires you can create a new one by first locating the asset you want to add the locator to and then creating the locator for that asset. Here's an example:

using Microsoft.WindowsAzure.MediaServices.Client;
using System;
using System.Linq;

namespace GenerateLocatorV2
{
    class Program
    {
        private static CloudMediaContext _context = null;
        static void Main(string[] args)
        {
            string tenantDomain = args[0];
            string RESTendpoint = args[1];
            string assetId = args[2];

            // Specify your AAD tenant domain, for example "microsoft.onmicrosoft.com"
            AzureAdTokenCredentials tokenCredentials = new AzureAdTokenCredentials(tenantDomain, AzureEnvironments.AzureCloudEnvironment);

            AzureAdTokenProvider tokenProvider = new AzureAdTokenProvider(tokenCredentials);

            // Specify your REST API endpoint, for example "https://accountname.restv2.westcentralus.media.azure.net/API"
            _context = new CloudMediaContext(new Uri(RESTendpoint), tokenProvider);

            IAsset asset = GetAsset(assetId);

            // Always try to reuse access policies.  You only need to configure one per type of access (30 day, read for example). 
            var tempPolicyId = from a in _context.AccessPolicies
                               where a.Name == "30DayRead"
                               select a;

            IAccessPolicy policy = null;

            if (tempPolicyId.Count() < 1)
            {
                // This will likely only run once ever to create the policy with this specific name.
                policy = _context.AccessPolicies.Create("30DayRead",
                TimeSpan.FromDays(30),
                AccessPermissions.Read);
            }
            else
            {
                // The policy exists already and has been found.
                policy = tempPolicyId.FirstOrDefault();
            }

            // Create a locator to the streaming content on an origin. 
            ILocator originLocator = _context.Locators.CreateLocator(LocatorType.OnDemandOrigin, asset,
                policy,
                DateTime.UtcNow.AddMinutes(-5));
        }
        private static IAsset GetAsset(string assetId)
        {
            var tempAsset = from a in _context.Assets
                            where a.Id == assetId
                            select a;
            IAsset asset = tempAsset.SingleOrDefault();
            return asset;
            // This function can be done in a single line by code like:
            // IAsset asset = _context.Assets.Where(a => a.Id == assetId).FirstOrDefault();
        }
    }
}


这篇关于Azure媒体服务定位器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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