gpt4 book ai didi

c# - Azure 媒体服务、具有 V3 api 的 GetLocators 和 ODataQuery

转载 作者:太空宇宙 更新时间:2023-11-03 12:05:55 26 4
gpt4 key购买 nike

我正在尝试使用 v3 API 和 Microsoft.Azure.Management.Media 获取给定 Assets 的所有流定位器包,但我使用 Odata 查询收到错误请求错误:

此行失败:var locator = client.StreamingLocators.List("webinars", "webinars", new ODataQuery<StreamingLocator>(x=>x.AssetName == assetId));

Microsoft.Azure.Management.Media.Models.ApiErrorException: Operation returned an invalid status code 'BadRequest'

当我在没有 ODataQuery 的情况下使用它时,它返回正常。

public IList<string> GetLocatorForAsset() {
var assetId = "bb4953cf-4793-4b3c-aed8-ae1bec88a339";
IList<string> streamingUrls = new List<string>();

var locator = client.StreamingLocators.List("webinars", "webinars", new ODataQuery<StreamingLocator>(x=>x.AssetName == assetId));
ListPathsResponse paths = client.StreamingLocators.ListPaths("webinars", "webinars", locator.FirstOrDefault().Name);

foreach (StreamingPath path in paths.StreamingPaths) {
UriBuilder uriBuilder = new UriBuilder();
uriBuilder.Scheme = "https";
uriBuilder.Host = "webinars-use2.streaming.media.azure.net";

uriBuilder.Path = path.Paths[0];
streamingUrls.Add(uriBuilder.ToString());
}

return streamingUrls;

}
}

最佳答案

根据媒体服务过滤文档,用户只能通过“名称”、“properties.created”和“properties.endTime”过滤“流定位器”。

https://learn.microsoft.com/en-us/azure/media-services/latest/entities-overview#streaming-locators

enter image description here

在您的示例中,您尝试使用不受支持的 assetId/assetName 进行过滤。因此出现 400 Bad request 错误。请参阅 postman 中的详细错误示例

enter image description here

这是使用流定位器“名称”标签的有效过滤示例。

注意:这不是 Assets 标签

enter image description here

用于使用“名称”成功过滤流定位器的 C# 示例

    try
{
// GUID need to be specified in single quote. using OData v 3.0
var odataquery = new ODataQuery<StreamingLocator>("name eq '65a1cb0d-ce7c-4470-93ac-fedf66450ea0'");
IPage<StreamingLocator> locators = client.StreamingLocators.List("mediatest", "mymediatestaccount", odataquery);

Console.WriteLine(locators.FirstOrDefault().Name);
Console.WriteLine(locators.FirstOrDefault().StreamingLocatorId);
Console.WriteLine(locators.FirstOrDefault().Id);

ListPathsResponse paths = client.StreamingLocators.ListPaths("mediatest", "mymediatestaccount", locators.FirstOrDefault().Name);

foreach (StreamingPath path in paths.StreamingPaths)
{
UriBuilder uriBuilder = new UriBuilder();
uriBuilder.Scheme = "https";
uriBuilder.Host = "webinars-use2.streaming.media.azure.net";

uriBuilder.Path = path.Paths[0];
Console.WriteLine(uriBuilder.ToString());
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}

我希望这会有所帮助。

关于c# - Azure 媒体服务、具有 V3 api 的 GetLocators 和 ODataQuery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55052728/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com