/// <summary> /// Provides a JSON formatted string for Download Requested Event Args /// </summary> public static JsonObject ToJsonObject(this AdaptiveMediaSourceDownloadRequestedEventArgs e) { var builder = new JsonBuilder("AdaptiveMediaSourceDownloadRequestedEventArgs"); builder.AddString("ResourceType", e.ResourceType); // builder.AddTimeSpan("Position", e.Position); // builder.AddNumber("RequestId", e.RequestId); builder.AddString("ResourceUri", e.ResourceUri); builder.AddNumber("ResourceByteRangeOffset", e.ResourceByteRangeOffset); builder.AddNumber("ResourceByteRangeLength", e.ResourceByteRangeLength); return(builder.GetJsonObject()); }
private void DownloadRequested(AdaptiveMediaSource sender, AdaptiveMediaSourceDownloadRequestedEventArgs args) { // rewrite key URIs to replace http:// with https:// if (args.ResourceType == AdaptiveMediaSourceResourceType.Key) { string originalUri = args.ResourceUri.ToString(); string secureUri = originalUri.Replace("http:", "https:"); // override the URI by setting property on the result sub object args.Result.ResourceUri = new Uri(secureUri); } }
private void ModifyKeyRequestUri(AdaptiveMediaSourceDownloadRequestedEventArgs args) { if (adaptiveContentModel == null) { return; } // This pattern can be used to modify Uris, for example: // To a redirect traffic to a secondary endpoint // To change an segment request into a byte-range Uri into another resource // Add the Bearer token to the Uri and modify the args.Result.ResourceUri string armoredAuthToken = System.Net.WebUtility.UrlEncode("Bearer=" + adaptiveContentModel.AesToken); string uriWithTokenParameter = $"{args.ResourceUri.AbsoluteUri}&token={armoredAuthToken}"; args.Result.ResourceUri = new Uri(uriWithTokenParameter); }
private async void DownloadRequested(AdaptiveMediaSource sender, AdaptiveMediaSourceDownloadRequestedEventArgs args) { // rewrite key URIs to replace http:// with https:// if (args.ResourceType == AdaptiveMediaSourceResourceType.Key) { string originalUri = args.ResourceUri.ToString(); string secureUri = originalUri.Replace("http:", "https:"); // override the URI by setting property on the result sub object args.Result.ResourceUri = new Uri(secureUri); } if (args.ResourceType == AdaptiveMediaSourceResourceType.Manifest) { AdaptiveMediaSourceDownloadRequestedDeferral deferral = args.GetDeferral(); // args.Result.Buffer = await CreateMyCustomManifest(args.ResourceUri); deferral.Complete(); } }
private void DownloadRequested(AdaptiveMediaSource sender, AdaptiveMediaSourceDownloadRequestedEventArgs args) { UpdateBitrateUI(txtMeasuredBandwidth, (uint)ams.InboundBitsPerSecond); }
private async Task AppDownloadedKeyRequest(AdaptiveMediaSourceDownloadRequestedEventArgs args) { if (adaptiveContentModel == null) { return; } // For AzureKeyAcquisitionMethod.ApplicationDownloaded we do the following: // Call .GetDeferral() to allow asynchronous work to be performed // Get the requested network resource using app code // Set .Result.InputStream or .Result.Buffer with the response data // Complete the deferral to indicate that we are done. // With this pattern, the app has complete control over any downloaded content. // Obtain a deferral so we can perform asynchronous operations. var deferral = args.GetDeferral(); try { var appHttpClientForKeys = new HttpClient(); appHttpClientForKeys.DefaultRequestHeaders.Authorization = new HttpCredentialsHeaderValue("Bearer", adaptiveContentModel.AesToken); HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, args.ResourceUri); HttpResponseMessage response = await appHttpClientForKeys.SendRequestAsync( request, HttpCompletionOption.ResponseHeadersRead).AsTask(ctsForAppHttpClientForKeys.Token); if (response.IsSuccessStatusCode) { args.Result.InputStream = await response.Content.ReadAsInputStreamAsync(); // Alternatively, we could use: // args.Result.Buffer = await response.Content.ReadAsBufferAsync(); } else { // The app code failed. Report this by setting the args.Result.ExtendedStatus. // This will ensure that the AdaptiveMediaSource does not attempt to download the resource // itself, and instead treats the download as having failed. switch (response.StatusCode) { case HttpStatusCode.Unauthorized: // HTTP_E_STATUS_DENIED args.Result.ExtendedStatus = 0x80190191; break; case HttpStatusCode.NotFound: // HTTP_E_STATUS_NOT_FOUND args.Result.ExtendedStatus = 0x80190194; break; default: // HTTP_E_STATUS_UNEXPECTED args.Result.ExtendedStatus = 0x80190001; break; } Log($"Key Download Failed: {response.StatusCode} {args.ResourceUri}"); } } catch (TaskCanceledException) { Log($"Request canceled: {args.ResourceUri}"); } catch (Exception e) { Log($"Key Download Failed: {e.Message} {args.ResourceUri}"); } finally { // Complete the deferral when done. deferral.Complete(); } }
private void _source_DownloadRequested(AdaptiveMediaSource sender, AdaptiveMediaSourceDownloadRequestedEventArgs args) { }
private void DownloadRequested(AdaptiveMediaSource sender, AdaptiveMediaSourceDownloadRequestedEventArgs args) { if (verbose) { Log($"DownloadRequested: {args.ResourceType}, {args.ResourceUri}"); } }
private async void DownloadRequested(AdaptiveMediaSource sender, AdaptiveMediaSourceDownloadRequestedEventArgs args) { if (args.ResourceType == AdaptiveMediaSourceResourceType.Key) { switch (tokenMethod) { case AzureKeyAcquisitionMethod.None: break; case AzureKeyAcquisitionMethod.AuthorizationHeader: // By updating the IHttpFilter KeyHost property here, we ensure it's up to date // before the network request is made. It is the IHttpFilter that will insert // the Authorization header. if (httpClientFilter != null) { httpClientFilter.KeyHost = args.ResourceUri.Host; } break; case AzureKeyAcquisitionMethod.UrlQueryParameter: ModifyKeyRequestUri(args); break; case AzureKeyAcquisitionMethod.ApplicationDownloaded: await AppDownloadedKeyRequest(args); break; default: break; } } }
private void DownloadRequested(AdaptiveMediaSource sender, AdaptiveMediaSourceDownloadRequestedEventArgs args) { logView.Log($"{args.ToJsonObject()}", LogViewLoggingLevel.Verbose); }