public async Task <LocatorsOutputModel> GetLocatorsAsync(InputRequestModel input) { bool didAbortBuildingUrl = false; LocatorsOutputModel allLocators = new LocatorsOutputModel { IsAllLive = false, IsAnyLive = false, LiveEvents = new List <LocatorsOutputModel.LiveEvent>() }; LoggerService.Info("Beginning the locators procedure", LoggerService.Locators); StreamingEndpoint streamingEndpoint = await GetStreamingEndpointAsync(input.StreamingEndpoint); LoggerService.Info($"Building {input.LiveEvents.Count} locator(s)", LoggerService.Locators); foreach (string liveEventName in input.LiveEvents) { List <LiveOutput> liveOutputs = await GetLiveOutputsAsync(liveEventName); if (!liveOutputs.Any()) { allLocators.LiveEvents.Add(GenerateEmptyLiveEvent(liveEventName)); didAbortBuildingUrl = true; LoggerService.Warn($"Could not find any live outputs for live event '{liveEventName}'", LoggerService.Locators); continue; } AssetStreamingLocator streamingLocator = await GetStreamingLocatorForAssetAsync(liveOutputs.First().AssetName); ListPathsResponse paths = await GetPathsForStreamingLocatorAsync(streamingLocator.Name); if (!paths.StreamingPaths.Any() || !paths.StreamingPaths.First().Paths.Any()) { allLocators.LiveEvents.Add(GenerateEmptyLiveEvent(liveEventName)); didAbortBuildingUrl = true; LoggerService.Warn($"Could not find any paths for the streaming locator '{streamingLocator.Name}' associated with the live event '{liveEventName}'", LoggerService.Locators); continue; } List <LocatorsOutputModel.LiveEvent.Locator> locators = MapStreamingPathsToLocatorUrls(streamingEndpoint.HostName, paths.StreamingPaths); allLocators.IsAnyLive = true; allLocators.LiveEvents.Add(new LocatorsOutputModel.LiveEvent { Name = liveEventName, IsLive = true, Locators = locators }); } LoggerService.Info($"Finished building {input.LiveEvents.Count} locator(s)", LoggerService.Locators); allLocators.IsAllLive = !didAbortBuildingUrl; return(allLocators); }
private async void comboBoxPolicyLocators_SelectedIndexChanged(object sender, EventArgs e) { AssetStreamingLocator locator = _locators[comboBoxPolicyLocators.SelectedIndex]; // _path = "/" + locator.StreamingLocatorId.ToString() + _path.Substring(_path.IndexOf('/', 2)); _path = (await _amsClient.AMSclient.StreamingLocators.ListPathsAsync(_amsClient.credentialsEntry.ResourceGroup, _amsClient.credentialsEntry.AccountName, locator.Name)) .StreamingPaths.Where(p => p.StreamingProtocol == StreamingPolicyStreamingProtocol.SmoothStreaming) .FirstOrDefault().Paths.FirstOrDefault(); UpdatePreviewUrl(); }
private async Task <AssetStreamingLocator> GetStreamingLocatorForAssetAsync(string assetName) { ListStreamingLocatorsResponse locatorResponse = await Client.Assets.ListStreamingLocatorsAsync( resourceGroupName : Config.ResourceGroup, accountName : Config.AccountName, assetName : assetName ); AssetStreamingLocator firstStreamingLocator = locatorResponse.StreamingLocators.First(); LoggerService.Info("Got the streaming locator for asset", LoggerService.Locators); return(firstStreamingLocator); }
public static async Task <(Uri, bool)> GetValidOnDemandSmoothURIAsync(Asset asset, IAzureMediaServicesClient client, string resourceGroup, string accountName, string useThisLocatorName = null, LiveOutput liveOutput = null) { bool emptyLiveOutput = false; // used to signal the live output is empty (do not use ListPathsAsync) IList <AssetStreamingLocator> locators = (await client.Assets.ListStreamingLocatorsAsync(resourceGroup, accountName, asset.Name)).StreamingLocators; Microsoft.Rest.Azure.IPage <StreamingEndpoint> ses = await client.StreamingEndpoints.ListAsync(resourceGroup, accountName); StreamingEndpoint runningSes = ses.Where(s => s.ResourceState == StreamingEndpointResourceState.Running).FirstOrDefault(); if (runningSes == null) { runningSes = ses.FirstOrDefault(); } if (locators.Count > 0 && runningSes != null) { string locatorName = useThisLocatorName ?? locators.First().Name; AssetStreamingLocator locatorToUse = locators.Where(l => l.Name == locatorName).First(); IList <StreamingPath> streamingPaths = (await client.StreamingLocators.ListPathsAsync(resourceGroup, accountName, locatorName)).StreamingPaths; IEnumerable <StreamingPath> smoothPath = streamingPaths.Where(p => p.StreamingProtocol == StreamingPolicyStreamingProtocol.SmoothStreaming); if (smoothPath.Any(s => s.Paths.Count != 0)) { UriBuilder uribuilder = new() { Host = runningSes.HostName, Path = smoothPath.FirstOrDefault().Paths.FirstOrDefault() }; return(uribuilder.Uri, emptyLiveOutput); } else if (smoothPath.Any() && liveOutput != null) // A live output with no data in it as live event not started. But we can determine the output URLs { UriBuilder uribuilder = new() { Host = runningSes.HostName, Path = locatorToUse.StreamingLocatorId.ToString() + "/" + liveOutput.ManifestName + ".ism/manifest" }; emptyLiveOutput = true; return(uribuilder.Uri, emptyLiveOutput); } else { return(null, emptyLiveOutput); } } else { return(null, emptyLiveOutput); } }