private string GetSource(IAzureMediaServicesClient client, Film film) { ListPathsResponse paths = client.StreamingLocators.ListPathsAsync(_config.Values.GetSection("ResourceGroup").Value, _config.Values.GetSection("AccountName").Value, film.AssetName + "Locator").Result; StreamingEndpoint streamingEndpoint = client.StreamingEndpoints.GetAsync(_config.Values.GetSection("ResourceGroup").Value, _config.Values.GetSection("AccountName").Value, "default").Result; string dashPath = ""; foreach (StreamingPath path in paths.StreamingPaths) { UriBuilder uriBuilder = new UriBuilder(); uriBuilder.Scheme = "https"; uriBuilder.Host = streamingEndpoint.HostName; // Look for just the DASH path and generate a URL for the Azure Media Player to playback the content with the AES token to decrypt. // Note that the JWT token is set to expire in 1 hour. if (path.StreamingProtocol == StreamingPolicyStreamingProtocol.Dash) { uriBuilder.Path = path.Paths[0]; dashPath = uriBuilder.ToString(); } } return(dashPath); }
/// <summary> /// Checks if the streaming endpoint is in the running state, /// if not, starts it. /// Then, builds the streaming URLs. /// </summary> /// <param name="client">The Media Services client.</param> /// <param name="resourceGroupName">The name of the resource group within the Azure subscription.</param> /// <param name="accountName"> The Media Services account name.</param> /// <param name="locatorName">The name of the StreamingLocator that was created.</param> /// <param name="streamingEndpoint">The streaming endpoint.</param> /// <param name="token">The CancellationToken.</param> /// <returns></returns> private async Task <IList <string> > GetStreamingUrlsAsync( IAzureMediaServicesClient client, string resourceGroupName, string accountName, String locatorName, StreamingEndpoint streamingEndpoint, CancellationToken token) { IList <string> streamingUrls = new List <string>(); ListPathsResponse paths = await client.StreamingLocators.ListPathsAsync(resourceGroupName, accountName, locatorName, token); foreach (StreamingPath path in paths.StreamingPaths) { _logger.LogInformation($"The following formats are available for {path.StreamingProtocol.ToString().ToUpper()}:"); foreach (string streamingFormatPath in path.Paths) { UriBuilder uriBuilder = new() { Scheme = "https", Host = streamingEndpoint.HostName, Path = streamingFormatPath }; _logger.LogInformation($"\t{uriBuilder}"); streamingUrls.Add(uriBuilder.ToString()); } } return(streamingUrls); }
/// <summary> /// Checks if the "default" streaming endpoint is in the running state, /// if not, starts it. /// Then, builds the streaming URLs. /// </summary> /// <param name="client">The Media Services client.</param> /// <param name="resourceGroupName">The name of the resource group within the Azure subscription.</param> /// <param name="accountName"> The Media Services account name.</param> /// <param name="locatorName">The name of the StreamingLocator that was created.</param> /// <param name="streamingEndpoint">The streaming endpoint.</param> /// <returns></returns> private static async Task <IList <string> > GetHLSAndDASHStreamingUrlsAsync( IAzureMediaServicesClient client, string resourceGroupName, string accountName, string locatorName, StreamingEndpoint streamingEndpoint) { IList <string> streamingUrls = new List <string>(); ListPathsResponse paths = await client.StreamingLocators.ListPathsAsync(resourceGroupName, accountName, locatorName); foreach (StreamingPath path in paths.StreamingPaths) { UriBuilder uriBuilder = new UriBuilder { Scheme = "https", Host = streamingEndpoint.HostName, Path = path.Paths[0] }; if (path.StreamingProtocol == StreamingPolicyStreamingProtocol.Hls) { streamingUrls.Add($"HLS url: {uriBuilder.ToString()}"); } else if (path.StreamingProtocol == StreamingPolicyStreamingProtocol.Dash) { streamingUrls.Add($"DASH url: {uriBuilder.ToString()}"); } } return(streamingUrls); }
public string GetStreamingUrl(StreamingLocator streamingLocator, string fileName) { UriBuilder uriBuilder = new UriBuilder() { Scheme = Constant.Media.Stream.DefaultScheme, Host = GetStreamingHost(null) }; ListPathsResponse paths = _media.StreamingLocators.ListPaths(MediaAccount.ResourceGroupName, MediaAccount.Name, streamingLocator.Name); if (!string.IsNullOrEmpty(fileName)) { foreach (string downloadPath in paths.DownloadPaths) { if (downloadPath.Contains(fileName)) { uriBuilder.Path = downloadPath; } } } else { foreach (StreamingPath streamingPath in paths.StreamingPaths) { if (streamingPath.StreamingProtocol == StreamingPolicyStreamingProtocol.SmoothStreaming && streamingPath.Paths.Count == 1) { uriBuilder.Path = streamingPath.Paths[0]; } } uriBuilder.Path = string.Concat(uriBuilder.Path, Constant.Media.Stream.DefaultFormat); } return(uriBuilder.ToString()); }
public ActionResult SetSources() { var client = CreateClient().Result; StreamingEndpoint streamingEndpoint = client.StreamingEndpoints.GetAsync(_config.GetSection("ResourceGroup").Value, _config.GetSection("AccountName").Value, "default").Result; var filmsToSource = db.Films.Where(f => f.AssetCreated && (f.Source == null || f.Source == "")).ToList(); foreach (Film film in filmsToSource) { ListPathsResponse paths = client.StreamingLocators.ListPathsAsync(_config.GetSection("ResourceGroup").Value, _config.GetSection("AccountName").Value, film.AssetName + "Locator").Result; string dashPath = ""; foreach (StreamingPath path in paths.StreamingPaths) { UriBuilder uriBuilder = new UriBuilder(); uriBuilder.Scheme = "https"; uriBuilder.Host = streamingEndpoint.HostName; // Look for just the DASH path and generate a URL for the Azure Media Player to playback the content with the AES token to decrypt. // Note that the JWT token is set to expire in 1 hour. if (path.StreamingProtocol == StreamingPolicyStreamingProtocol.Dash) { uriBuilder.Path = path.Paths[0]; dashPath = uriBuilder.ToString(); } } SetSource(film.FilmID, dashPath); } return(Content("OK")); }
/// <summary> /// Checks if the "default" streaming endpoint is in the running state, /// if not, starts it. /// Then, builds the streaming URLs. /// </summary> /// <param name="client">The Media Services client.</param> /// <param name="resourceGroupName">The name of the resource group within the Azure subscription.</param> /// <param name="accountName"> The Media Services account name.</param> /// <param name="locatorName">The name of the StreamingLocator that was created.</param> /// <param name="streamingEndpoint">The streaming endpoint.</param> /// <returns></returns> private static async Task <string> GetDASHStreamingUrlAsync( IAzureMediaServicesClient client, string resourceGroupName, string accountName, string locatorName, StreamingEndpoint streamingEndpoint) { string dashPath = ""; ListPathsResponse paths = await client.StreamingLocators.ListPathsAsync(resourceGroupName, accountName, locatorName); foreach (StreamingPath path in paths.StreamingPaths) { UriBuilder uriBuilder = new UriBuilder { Scheme = "https", Host = streamingEndpoint.HostName }; // Look for just the DASH path and generate a URL for the Azure Media Player to playback the encrypted DASH content. // Note that the JWT token is set to expire in 1 hour. if (path.StreamingProtocol == StreamingPolicyStreamingProtocol.Dash) { uriBuilder.Path = path.Paths[0]; dashPath = uriBuilder.ToString(); } } return(dashPath); }
/// <summary> /// Builds the HLS streaming URL. /// </summary> /// <param name="client">The Media Services client.</param> /// <param name="resourceGroupName">The name of the resource group within the Azure subscription.</param> /// <param name="accountName"> The Media Services account name.</param> /// <param name="locatorName">The name of the StreamingLocator that was created.</param> /// <param name="streamingEndpoint">The streaming endpoint.</param> /// <returns></returns> private static async Task <string> GetHlsStreamingUrlAsync(IAzureMediaServicesClient client, string resourceGroupName, string accountName, string locatorName, StreamingEndpoint streamingEndpoint) { string hlsPath = ""; ListPathsResponse paths = await client.StreamingLocators.ListPathsAsync(resourceGroupName, accountName, locatorName); foreach (StreamingPath path in paths.StreamingPaths) { UriBuilder uriBuilder = new() { Scheme = "https", Host = streamingEndpoint.HostName }; // Look for just the HLS path and generate a URL for Apple device to playback the encrypted content. if (path.StreamingProtocol == StreamingPolicyStreamingProtocol.Hls) { uriBuilder.Path = path.Paths[0]; hlsPath = uriBuilder.ToString(); } } return(hlsPath); }
// </CreateStreamingLocator> /// <summary> /// Checks if the "default" streaming endpoint is in the running state, /// if not, starts it. /// Then, builds the streaming URLs. /// </summary> /// <param name="client">The Media Services client.</param> /// <param name="resourceGroupName">The name of the resource group within the Azure subscription.</param> /// <param name="accountName"> The Media Services account name.</param> /// <param name="locatorName">The name of the StreamingLocator that was created.</param> /// <returns></returns> // <GetStreamingURLs> private static 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); }
// </CreateStreamingLocatorAsync> /// <summary> /// Checks if the "default" streaming endpoint is in the running state, /// if not, starts it. /// Then, builds the streaming URLs. /// </summary> /// <param name="client">The Media Services client.</param> /// <param name="resourceGroupName">The name of the resource group within the Azure subscription.</param> /// <param name="accountName"> The Media Services account name.</param> /// <param name="locatorName">The name of the StreamingLocator that was created.</param> /// <returns></returns> // <GetStreamingUrlsAsync> private static async Task <IList <string> > GetStreamingUrlsAsync( IAzureMediaServicesClient client, string resourceGroupName, string accountName, String locatorName) { const string DefaultStreamingEndpointName = "default"; IList <string> streamingUrls = new List <string>(); string streamingUrlPrefix = string.Empty; StreamingEndpoint streamingEndpoint = await client.StreamingEndpoints.GetAsync(resourceGroupName, accountName, DefaultStreamingEndpointName); if (streamingEndpoint != null) { streamingUrlPrefix = streamingEndpoint.HostName; 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) { streamingUrls.Add($"//{streamingUrlPrefix}{path.Paths[0]}"); } return(streamingUrls); }
/// <summary> /// Checks if the streaming endpoint is in the running state, /// if not, starts it. Then, builds the streaming URLs. /// </summary> /// <param name="client">The Media Services client.</param> /// <param name="resourceGroupName">The name of the resource group within the Azure subscription.</param> /// <param name="accountName"> The Media Services account name.</param> /// <param name="locatorName">The name of the StreamingLocator that was created.</param> /// <param name="streamingEndpoint">The streaming endpoint.</param> /// <returns>A task.</returns> private static async Task <IList <string> > GetStreamingUrlsAsync( IAzureMediaServicesClient client, string resourceGroupName, string accountName, String locatorName, StreamingEndpoint streamingEndpoint) { IList <string> streamingUrls = new List <string>(); ListPathsResponse paths = await client.StreamingLocators.ListPathsAsync(resourceGroupName, accountName, locatorName); foreach (StreamingPath path in paths.StreamingPaths) { UriBuilder uriBuilder = new UriBuilder { Scheme = "https", Host = streamingEndpoint.HostName, Path = path.Paths[0] }; streamingUrls.Add(uriBuilder.ToString()); } return(streamingUrls); }
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 Task <ListPathsResponse> GetPathsForStreamingLocatorAsync(string streamingLocatorName) { ListPathsResponse paths = await Client.StreamingLocators.ListPathsAsync( resourceGroupName : Config.ResourceGroup, accountName : Config.AccountName, streamingLocatorName : streamingLocatorName ); LoggerService.Info("Got the paths for the streaming locator", LoggerService.Locators); return(paths); }
/// <summary> /// This function returns a Dash or HLS Uri from the pathResponse. /// It also adds .mpd or .m3u8 at the end of the URL for a better compatibility with media players. /// </summary> /// <param name="pathResponse">Response from AMS on list paths.</param> /// <param name="selectedStreamingEndpoint">The selected streaming endpoint.</param> /// <param name="protocol">The protocol selected.</param> /// <returns>The streaming Uri, if available, or null.</returns> private static Uri GetStreamingUri(ListPathsResponse pathResponse, StreamingEndpoint selectedStreamingEndpoint, StreamingPolicyStreamingProtocol protocol) { string uristr = pathResponse.StreamingPaths.Where(p => p.StreamingProtocol == protocol).FirstOrDefault()?.Paths.FirstOrDefault(); if (uristr != null) { uristr = "https://" + selectedStreamingEndpoint.HostName + uristr; if (!uristr.EndsWith(ExtensionPerProtocol[protocol])) { uristr += ExtensionPerProtocol[protocol]; } } return(uristr != null ? new Uri(uristr) : null); }
private static string GetStreamingUrlsAndDrmType(IAzureMediaServicesClient client, string resourceGroupName, string accountName, String locatorName) { string streamingUrl = string.Empty; ListPathsResponse paths = client.StreamingLocators.ListPaths(resourceGroupName, accountName, locatorName); foreach (StreamingPath path in paths.StreamingPaths) { if (path.StreamingProtocol == StreamingPolicyStreamingProtocol.SmoothStreaming) { UriBuilder uriBuilder = new UriBuilder(); uriBuilder.Scheme = "https"; uriBuilder.Host = streamingEndpoint.HostName; uriBuilder.Path = path.Paths[0]; streamingUrl = uriBuilder.ToString(); } } return(streamingUrl); }
// </GetToken> /// <summary> /// Checks if the "default" streaming endpoint is in the running state, /// if not, starts it. /// Then, builds the streaming URLs. /// </summary> /// <param name="client">The Media Services client.</param> /// <param name="resourceGroupName">The name of the resource group within the Azure subscription.</param> /// <param name="accountName"> The Media Services account name.</param> /// <param name="locatorName">The name of the StreamingLocator that was created.</param> /// <returns></returns> // <GetMPEGStreamingUrl> private static async Task <string> GetDASHStreamingUrlAsync( IAzureMediaServicesClient client, string resourceGroupName, string accountName, string locatorName) { const string DefaultStreamingEndpointName = "default"; string dashPath = ""; 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 { Scheme = "https", Host = streamingEndpoint.HostName }; // Look for just the DASH path and generate a URL for the Azure Media Player to playback the content with the AES token to decrypt. // Note that the JWT token is set to expire in 1 hour. if (path.StreamingProtocol == StreamingPolicyStreamingProtocol.Dash) { uriBuilder.Path = path.Paths[0]; dashPath = uriBuilder.ToString(); } } return(dashPath); }
public string GetPlayerUrl(StreamingLocator locator) { string playerUrl = string.Empty; ListPathsResponse paths = _media.StreamingLocators.ListPaths(MediaAccount.ResourceGroupName, MediaAccount.Name, locator.Name); foreach (StreamingPath streamingPath in paths.StreamingPaths) { if (streamingPath.StreamingProtocol == StreamingPolicyStreamingProtocol.SmoothStreaming && streamingPath.Paths.Count == 1) { playerUrl = streamingPath.Paths[0]; } } if (string.IsNullOrEmpty(playerUrl) && paths.DownloadPaths.Count == 1) { playerUrl = paths.DownloadPaths[0]; } if (!string.IsNullOrEmpty(playerUrl)) { playerUrl = GetDefaultUrl(playerUrl); } return(playerUrl); }
// Check the Streaming Endpoint is running and retrieve the DASH URL private static async Task <string> GetStreamingUrlAsync(IAzureMediaServicesClient client, string resourceGroupName, string accountName, string locatorName, StreamingEndpoint streamingEndpoint) { string dashPath = ""; ListPathsResponse paths = await client.StreamingLocators.ListPathsAsync(resourceGroupName, accountName, locatorName); foreach (StreamingPath path in paths.StreamingPaths) { UriBuilder uriBuilder = new UriBuilder { Scheme = "https", Host = streamingEndpoint.HostName }; if (path.StreamingProtocol == StreamingPolicyStreamingProtocol.Dash) { uriBuilder.Path = path.Paths[0]; dashPath = uriBuilder.ToString(); } } return(dashPath); }
/// <summary> /// Returns a list of streaming Uri's /// </summary> /// <param name="OutputName">Name of the song to play</param> /// <returns>A task of type IList < string > </string></returns> public static async Task <IList <string> > StreamingUri(string OutputName) { var streamingUrls = new List <string> (); var uriBuilder = new UriBuilder(); var locator = await _client.StreamingLocators.GetAsync( _configuration.ResourceGroup, _configuration.AccountName, "Locator-" + (OutputName.Contains(".") ? OutputName.Split(".") [0] : OutputName) ); if (locator == null) { locator = await _client.StreamingLocators.CreateAsync( _configuration.ResourceGroup, _configuration.AccountName, "Locator-" + (OutputName.Contains(".") ? OutputName.Split(".") [0] : OutputName), new StreamingLocator { AssetName = "Output-" + (OutputName.Contains(".") ? OutputName.Split(".") [0] : OutputName), StreamingPolicyName = PredefinedStreamingPolicy.ClearStreamingOnly } ); } var streamingEndpoint = await _client.StreamingEndpoints.GetAsync( _configuration.ResourceGroup, _configuration.AccountName, "default" ); if (streamingEndpoint != null) { if (streamingEndpoint.ResourceState != StreamingEndpointResourceState.Running) { await _client.StreamingEndpoints.StartAsync( _configuration.ResourceGroup, _configuration.AccountName, "default" ); } } ListPathsResponse paths = await _client.StreamingLocators.ListPathsAsync( _configuration.ResourceGroup, _configuration.AccountName, locator.Name ); uriBuilder.Scheme = "https"; uriBuilder.Host = streamingEndpoint.HostName; foreach (var path in paths.StreamingPaths) { uriBuilder.Path = path.Paths [0]; streamingUrls.Add(uriBuilder.ToString()); } return(streamingUrls); }
/// <inheritdoc/> public async Task <ServiceOperationResultMediaServicesV3LocatorCreate> LocatorCreateAsync( Uri containerUri, string streamingPolicyName, string contentKeyPolicyName, TimeBasedFilterDTO timeBasedFilterInfo, JObject operationContext, bool generateAudioFilters) { TimeSpan?startTimeSpan = null; TimeSpan?endTimeSpan = null; if (!(timeBasedFilterInfo is null)) { if (timeBasedFilterInfo.StartSeconds < 0) { throw new GridwichTimeParameterException(nameof(timeBasedFilterInfo.StartSeconds), timeBasedFilterInfo.StartSeconds, "Must be above zero."); } startTimeSpan = TimeSpan.FromSeconds(timeBasedFilterInfo.StartSeconds); if (timeBasedFilterInfo.EndSeconds < 0) { throw new GridwichTimeParameterException(nameof(timeBasedFilterInfo.EndSeconds), timeBasedFilterInfo.EndSeconds, "Must be above zero."); } endTimeSpan = TimeSpan.FromSeconds(timeBasedFilterInfo.EndSeconds); } await ConnectAsync().ConfigureAwait(false); string streamingPolicy = await GetStreamingPolicyAmsNameAsync(streamingPolicyName).ConfigureAwait(false); string assetName = await GetAssetNameAsync(containerUri).ConfigureAwait(false); string uniqueness = Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture).Substring(0, 11); List <string> listFilters = await GetListFiltersAsync(startTimeSpan, endTimeSpan, uniqueness, assetName).ConfigureAwait(false); if (generateAudioFilters) { var listAudioTracks = await GetAudioTracks(containerUri).ConfigureAwait(false); // Once we have the list of audio tracks, we want to order them by their track index, then create filter names starting at 0: int filterIndex = 0; foreach (var audioTrack in listAudioTracks.OrderBy(t => t.TrackID)) { string filterName = string.Format(CultureInfo.InvariantCulture, "audio{0:00}", filterIndex++); await CreateTrackFilterAsync(assetName, filterName, new List <TrackInfo>() { audioTrack }).ConfigureAwait(false); } // In the future, we might want to create a filter for each audio with the video: // filterIndex = 0; // var videoTrack = new TrackInfo() { TrackID = 1, TrackName = "video", TrackType = "Video" }; // foreach (var audioTrack in listAudioTracks.OrderBy(t => t.TrackID)) // { // string filterName = string.Format(CultureInfo.InvariantCulture, "video00audio{0:00}", filterIndex++); // await CreateTrackFilterAsync( // assetName, // filterName, // new List<TrackInfo>() // { // audioTrack, // videoTrack // }).ConfigureAwait(false); // } } string defaultContentKeyPolicyName = await GetDefaultContentKeyPolicyNameAsync(contentKeyPolicyName).ConfigureAwait(false); string locatorName = "locator-" + uniqueness; StreamingLocator locatorCreated = await CreateLocatorAsync( locatorName, assetName, listFilters, streamingPolicy, defaultContentKeyPolicyName).ConfigureAwait(false); StreamingEndpoint selectedStreamingEndpoint = await GetSelectedStreamingEndpointAsync().ConfigureAwait(false); ListPathsResponse pathResponse = await GetListPathResponseAsync(locatorName).ConfigureAwait(false); Uri dashUri = GetStreamingUri(pathResponse, selectedStreamingEndpoint, StreamingPolicyStreamingProtocol.Dash); Uri hlsUri = GetStreamingUri(pathResponse, selectedStreamingEndpoint, StreamingPolicyStreamingProtocol.Hls); // Getting the keys id var cencKey = locatorCreated.ContentKeys.Where(k => k.Type == StreamingLocatorContentKeyType.CommonEncryptionCenc).FirstOrDefault(); var cbcsKey = locatorCreated.ContentKeys.Where(k => k.Type == StreamingLocatorContentKeyType.CommonEncryptionCbcs).FirstOrDefault(); string cencKeyId = cencKey?.Id.ToString(); string cbcsKeyId = cbcsKey?.Id.ToString(); return(new ServiceOperationResultMediaServicesV3LocatorCreate( locatorName, cencKeyId, cbcsKeyId, dashUri, hlsUri, operationContext)); }
static public PublishAssetOutput ConvertToPublishAssetOutput(string locatorName, string streamingUrlPrefx, ListPathsResponse paths) { PublishAssetOutput output = new PublishAssetOutput(); output.locatorName = locatorName; output.streamingUrl = ""; output.captionVttUrl = ""; output.annotationsJsonUrl = ""; output.contentModerationJsonUrl = ""; output.facesJsonUrl = ""; output.insightsJsonUrl = ""; output.ocrJsonUrl = ""; List <PublishStreamingUrls> psUrls = new List <PublishStreamingUrls>(); foreach (var path in paths.StreamingPaths) { var s = new PublishStreamingUrls(); s.streamingProtocol = path.StreamingProtocol; s.encryptionScheme = path.EncryptionScheme; s.urls = new string[path.Paths.Count]; for (int i = 0; i < path.Paths.Count; i++) { s.urls[i] = "https://" + streamingUrlPrefx + path.Paths[i]; } if (path.StreamingProtocol == "SmoothStreaming") { output.streamingUrl = "https://" + streamingUrlPrefx + path.Paths[0]; } psUrls.Add(s); } output.streamingUrls = psUrls.ToArray(); List <string> dUrls = new List <string>(); foreach (var path in paths.DownloadPaths) { dUrls.Add("https://" + streamingUrlPrefx + path); if (path.EndsWith("annotations.json")) { output.annotationsJsonUrl = "https://" + streamingUrlPrefx + path; } if (path.EndsWith("contentmoderation.json")) { output.contentModerationJsonUrl = "https://" + streamingUrlPrefx + path; } if (path.EndsWith("faces.json")) { output.facesJsonUrl = "https://" + streamingUrlPrefx + path; } if (path.EndsWith("insights.json")) { output.insightsJsonUrl = "https://" + streamingUrlPrefx + path; } if (path.EndsWith("transcript.vtt")) { output.captionVttUrl = "https://" + streamingUrlPrefx + path; } } output.downloadUrls = dUrls.ToArray(); return(output); }
public static async Task <object> Run([HttpTrigger(WebHookType = "genericJson")] HttpRequestMessage req, TraceWriter log) { log.Info($"AMS v3 Function - publish_asset was triggered!"); string jsonContent = await req.Content.ReadAsStringAsync(); dynamic data = JsonConvert.DeserializeObject(jsonContent); // Validate input objects if (data.publishAssetName == null) { return(req.CreateResponse(HttpStatusCode.BadRequest, new { error = "Please pass publishAssetName in the input object" })); } string publishAssetName = data.publishAssetName; PredefinedStreamingPolicy streamingPolicy = PredefinedStreamingPolicy.ClearStreamingOnly; // default if (data.streamingPolicy != null) { string streamingPolicyName = data.streamingPolicy; if (predefinedStreamingPolicy.ContainsKey(streamingPolicyName)) { streamingPolicy = predefinedStreamingPolicy[streamingPolicyName]; } } string streamingEndpointName = "default"; // default if (data.streamingEndpointName != null) { streamingEndpointName = data.streamingEndpointName; } MediaServicesConfigWrapper amsconfig = new MediaServicesConfigWrapper(); string guid = Guid.NewGuid().ToString(); string locatorName = "locator-" + guid; PublishAssetOutput output = null; try { IAzureMediaServicesClient client = CreateMediaServicesClient(amsconfig); StreamingLocator locator = client.StreamingLocators.Create(amsconfig.ResourceGroup, amsconfig.AccountName, locatorName, new StreamingLocator() { AssetName = publishAssetName, StreamingPolicyName = streamingPolicy, }); string streamingUrlPrefx = ""; StreamingEndpoint streamingEndpoint = client.StreamingEndpoints.Get(amsconfig.ResourceGroup, amsconfig.AccountName, streamingEndpointName); if (streamingEndpoint != null) { streamingUrlPrefx = streamingEndpoint.HostName; } ListPathsResponse paths = client.StreamingLocators.ListPaths(amsconfig.ResourceGroup, amsconfig.AccountName, locatorName); output = MediaServicesHelper.ConvertToPublishAssetOutput(locatorName, streamingUrlPrefx, paths); } catch (ApiErrorException e) { log.Info($"ERROR: AMS API call failed with error code: {e.Body.Error.Code} and message: {e.Body.Error.Message}"); return(req.CreateResponse(HttpStatusCode.BadRequest, new { error = "AMS API call error: " + e.Message })); } return(req.CreateResponse(HttpStatusCode.OK, output)); }