Azure媒体播放器如何获取播放器的源URL

时间:2019-10-02 12:38:20

标签: azure-media-services azure-media-player

我有一个天蓝色的媒体服务帐户,上面有一些上传的视频,但是这些视频只能在浏览器上播放,并带有一些其他参数(如ss = 2017-04-17&sr = c&sig = QMSr ...),如身份验证密钥。 我想要一个可以随时播放的通用永久渐进式视频URL,我尝试将Azure媒体播放器与带有.ism / manifest和.mp4的视频URL一起使用,但两者均无法播放 exp:

https://<MY_BLOBSTORAGE_ACCOUNT>.blob.core.windows.net/<Asset-ID>/Video_FILE_NAME>.ism/manifest

https://<MY_BLOBSTORAGE_ACCOUNT>.blob.core.windows.net/<Asset-ID>/<Video_FILE_NAME>_1280x720_AACAudio.mp4

我已经尝试从此正式的Microsoft文档中播放该播放器: http://amp.azure.net/libs/amp/latest/docs/index.html#full-setup-of-azure-media-player

还请注意,Azure Media Services V3文档以及ams本身的社区在解释以编程方式获取播放器视频网址的步骤方面非常贫乏。

3 个答案:

答案 0 :(得分:0)

看来您正在混合渐进式下载和流式传输。我在https://blogs.msdn.microsoft.com/randomnumber/2016/03/23/progressive-download-and-streaming-differences-with-azure-media-services/上写了一篇博客文章,介绍与Azure媒体服务有关的差异。如果您将视频编码为自适应比特率MP4集,则很有可能希望流传输视频,而不是在单个MP4上使用渐进式下载。这可能对流媒体方面有所帮助:https://docs.microsoft.com/en-us/azure/media-services/latest/dynamic-packaging-overview

答案 1 :(得分:0)

使用AMS v3,您将必须创建流定位器,并且可以使用预构建的流策略。有政策 -仅流式 -流媒体和下载 -仅下载

使用下载策略,您将获得资产中每个blob的URL。例如 : https://myaccount-uswc.streaming.media.azure.net/1544fcae-a248-4f53-b653-cd02074b04b6/video_848x480_2200.mp4

使用流策略(推荐),您将获得DASH,HLS和Smooth URL,例如: https://myaccount-uswc.streaming.media.azure.net/0eef6f88-47c6-4662-9111-60305d7c1000/video.ism/manifest(format=mpd-time-csf).mpd

答案 2 :(得分:0)

我在朋友的帮助下找到了解决方案,创建了流定位器后,我必须确保流终结点正在运行,然后通过遍历需要使用StreamingLocators.ListPathsAsync的路径来获取构建URL。 ,下面是代码段。

        private async Task<StreamingLocator> CreateStreamingLocatorAsync(
            IAzureMediaServicesClient client,
            string resourceGroup,
            string accountName,
            string assetName,
            string locatorName)
        {
            StreamingLocator locator = await client.StreamingLocators.CreateAsync(
                resourceGroup,
                accountName,
                locatorName,
                new StreamingLocator
                {
                    AssetName = assetName,
                    StreamingPolicyName = PredefinedStreamingPolicy.ClearStreamingOnly
                });

            return locator;
        }

        private async Task<IList<string>> GetStreamingUrlsAsync(
            IAzureMediaServicesClient client,
            string resourceGroupName,
            string accountName,
            String locatorName)
        {
            const string DefaultStreamingEndpointName = "default";

            IList<string> streamingUrls = new List<string>();

            StreamingEndpoint streamingEndpoint = await client.StreamingEndpoints.GetAsync(resourceGroupName, accountName, DefaultStreamingEndpointName);

            if (streamingEndpoint != null)
            {
                if (streamingEndpoint.ResourceState != StreamingEndpointResourceState.Running)
                {
                    await client.StreamingEndpoints.StartAsync(resourceGroupName, accountName, DefaultStreamingEndpointName);
                }
            }

            ListPathsResponse paths = await client.StreamingLocators.ListPathsAsync(resourceGroupName, accountName, locatorName);

            foreach (StreamingPath path in paths.StreamingPaths)
            {
                UriBuilder uriBuilder = new UriBuilder();
                uriBuilder.Scheme = "https";
                uriBuilder.Host = streamingEndpoint.HostName;

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

            return streamingUrls;
        }

并在我的服务方法中执行以下操作:

StreamingLocator locator = await CreateStreamingLocatorAsync(client,
config.ResourceGroup, config.AccountName, outputAsset.Name, locatorName);

IList<string> streamingUrls = await GetStreamingUrlsAsync(client, config.ResourceGroup, config.AccountName, locator.Name);
foreach (var url in streamingUrls)
   {
       urls.Add(url);
       Console.WriteLine(url);
   }
myModel.StreamingUrls = urls;