private async Task <MediaPlaybackItem> LoadSourceFromUriAsync(Uri uri, HttpClient httpClient = null) { UnregisterHandlers(mediaPlayerElement.MediaPlayer); AdaptiveMediaSourceCreationResult result = null; if (httpClient != null) { result = await AdaptiveMediaSource.CreateFromUriAsync(uri, httpClient); } else { result = await AdaptiveMediaSource.CreateFromUriAsync(uri); } MediaSource source; if (result.Status == AdaptiveMediaSourceCreationStatus.Success) { var adaptiveMediaSource = result.MediaSource; // We use a helper class that logs all the events for the AdaptiveMediaSource: adaptiveMediaSourceLogger = new AdaptiveMediaSourceLogger(LoggerControl, adaptiveMediaSource); source = MediaSource.CreateFromAdaptiveMediaSource(adaptiveMediaSource); } else { Log($"Error creating the AdaptiveMediaSource. Status: {result.Status}, ExtendedError.Message: {result.ExtendedError.Message}, ExtendedError.HResult: {result.ExtendedError.HResult.ToString("X8")}"); return(null); } // We use a helper class that logs all the events for the MediaSource: mediaSourceLogger = new MediaSourceLogger(LoggerControl, source); // Save the original Uri. source.CustomProperties["uri"] = uri.ToString(); // You're likely to put a content tracking id into the CustomProperties. source.CustomProperties["contentId"] = "MainContent_ID"; // In addition to logging, this scenario uses MediaSource events: RegisterForMediaSourceEvents(source); var mpItem = new MediaPlaybackItem(source); // We use a helper class that logs all the events for the MediaPlaybackItem: mediaPlaybackItemLogger = new MediaPlaybackItemLogger(LoggerControl, mpItem); // In addition to logging, this scenario uses MediaPlaybackItem events: RegisterForMediaPlaybackItemEvents(mpItem); // Now that we should have a MediaPlaybackItem, we will insert pre- mid- and post-roll ads // with the MediaBreak API. CreateMediaBreaksForItem(mpItem); HideDescriptionOnSmallScreen(); return(mpItem); }
private async Task <MediaPlaybackItem> LoadSourceFromUriAsync(Uri uri, HttpClient httpClient = null) { UnregisterHandlers(mediaPlayerElement.MediaPlayer); mediaPlayerElement.MediaPlayer?.DisposeSource(); AdaptiveMediaSourceCreationResult result = null; if (httpClient != null) { result = await AdaptiveMediaSource.CreateFromUriAsync(uri, httpClient); } else { result = await AdaptiveMediaSource.CreateFromUriAsync(uri); } MediaSource source; if (result.Status == AdaptiveMediaSourceCreationStatus.Success) { adaptiveMediaSource = result.MediaSource; // We use a helper class that logs all the events for the AdaptiveMediaSource: adaptiveMediaSourceLogger = new AdaptiveMediaSourceLogger(LoggerControl, adaptiveMediaSource); // In addition to logging, we use the callbacks to update some UI elements in this scenario: RegisterForAdaptiveMediaSourceEvents(adaptiveMediaSource); // At this point, we have read the manifest of the media source, and all bitrates are known. bitrateHelper = new BitrateHelper(adaptiveMediaSource.AvailableBitrates); InitializeBitrateLists(adaptiveMediaSource); await UpdatePlaybackBitrateAsync(adaptiveMediaSource.CurrentPlaybackBitrate); await UpdateDownloadBitrateAsync(adaptiveMediaSource.CurrentDownloadBitrate); source = MediaSource.CreateFromAdaptiveMediaSource(adaptiveMediaSource); } else { Log($"Error creating the AdaptiveMediaSource. Status: {result.Status}, ExtendedError.Message: {result.ExtendedError.Message}, ExtendedError.HResult: {result.ExtendedError.HResult.ToString("X8")}"); return(null); } // We use a helper class that logs all the events for the MediaSource: mediaSourceLogger = new MediaSourceLogger(LoggerControl, source); // Save the original Uri. source.CustomProperties["uri"] = uri.ToString(); // You're likely to put a content tracking id into the CustomProperties. source.CustomProperties["contentId"] = Guid.NewGuid().ToString(); var mpItem = new MediaPlaybackItem(source); // We use a helper class that logs all the events for the MediaPlaybackItem: mediaPlaybackItemLogger = new MediaPlaybackItemLogger(LoggerControl, mpItem); HideDescriptionOnSmallScreen(); return(mpItem); }
private async Task <MediaPlaybackItem> LoadSourceFromUriAsync(Uri uri, HttpClient httpClient = null) { UnregisterHandlers(mediaPlayerElement.MediaPlayer); mediaPlayerElement.MediaPlayer?.DisposeSource(); AdaptiveMediaSourceCreationResult result = null; if (httpClient != null) { result = await AdaptiveMediaSource.CreateFromUriAsync(uri, httpClient); } else { result = await AdaptiveMediaSource.CreateFromUriAsync(uri); } MediaSource source; if (result.Status == AdaptiveMediaSourceCreationStatus.Success) { var adaptiveMediaSource = result.MediaSource; // We use a helper class that logs all the events for the AdaptiveMediaSource: adaptiveMediaSourceLogger = new AdaptiveMediaSourceLogger(LoggerControl, adaptiveMediaSource); source = MediaSource.CreateFromAdaptiveMediaSource(adaptiveMediaSource); if (adaptiveMediaSource.MaxSeekableWindowSize.HasValue) { UpdateSeekableWindowControls(adaptiveMediaSource); } } else { Log($"Error creating the AdaptiveMediaSource. Status: {result.Status}, ExtendedError.Message: {result.ExtendedError.Message}, ExtendedError.HResult: {result.ExtendedError.HResult.ToString("X8")}"); return(null); } // We use a helper class that logs all the events for the MediaSource: mediaSourceLogger = new MediaSourceLogger(LoggerControl, source); // Save the original Uri. source.CustomProperties["uri"] = uri.ToString(); // You're likely to put a content tracking id into the CustomProperties. source.CustomProperties["contentId"] = Guid.NewGuid().ToString(); var mpItem = new MediaPlaybackItem(source); // We use a helper class that logs all the events for the MediaPlaybackItem: mediaPlaybackItemLogger = new MediaPlaybackItemLogger(LoggerControl, mpItem); HideDescriptionOnSmallScreen(); return(mpItem); }
private async Task <MediaPlaybackItem> LoadSourceFromUriAsync(Uri uri, HttpClient httpClient = null) { UnregisterHandlers(mediaPlayerElement.MediaPlayer); AdaptiveMediaSourceCreationResult result = null; if (httpClient != null) { result = await AdaptiveMediaSource.CreateFromUriAsync(uri, httpClient); } else { result = await AdaptiveMediaSource.CreateFromUriAsync(uri); } MediaSource source; if (result.Status == AdaptiveMediaSourceCreationStatus.Success) { var adaptiveMediaSource = result.MediaSource; // We use a helper class that logs all the events for the AdaptiveMediaSource: adaptiveMediaSourceLogger = new AdaptiveMediaSourceLogger(LoggerControl, adaptiveMediaSource); // In addition to logging, we use the callbacks to update some UI elements in this scenario: RegisterForAdaptiveMediaSourceEvents(adaptiveMediaSource); // At this point, we have read the manifest of the media source, and all bitrates are known. bitrateHelper = new BitrateHelper(adaptiveMediaSource.AvailableBitrates); // The AdaptiveMediaSource chooses initial playback and download bitrates. // See the Tuning scenario for examples of customizing these bitrates. await UpdatePlaybackBitrateAsync(adaptiveMediaSource.CurrentPlaybackBitrate); await UpdateDownloadBitrateAsync(adaptiveMediaSource.CurrentDownloadBitrate); source = MediaSource.CreateFromAdaptiveMediaSource(adaptiveMediaSource); } else { Log($"Error creating the AdaptiveMediaSource. Status: {result.Status}, ExtendedError.Message: {result.ExtendedError.Message}, ExtendedError.HResult: {result.ExtendedError.HResult.ToString("X8")}"); // In this scenario, we make a second attempt to load any URI that is // not adaptive streaming as a progressive download URI: Log($"Attempting to create a MediaSource from uri: {uri}"); source = MediaSource.CreateFromUri(uri); } // We use a helper class that logs all the events for the MediaSource: mediaSourceLogger = new MediaSourceLogger(LoggerControl, source); // You can save additional information in the CustomPropertySet for future retrieval. // Note: MediaSource.CustomProperties is a ValueSet and therefore can store // only serializable types. // Save the original Uri. source.CustomProperties["uri"] = uri.ToString(); // You're likely to put a content tracking id into the CustomProperties. source.CustomProperties["contentId"] = Guid.NewGuid().ToString(); var mpItem = new MediaPlaybackItem(source); // We use a helper class that logs all the events for the MediaPlaybackItem: mediaPlaybackItemLogger = new MediaPlaybackItemLogger(LoggerControl, mpItem); HideDescriptionOnSmallScreen(); return(mpItem); }
private async Task <MediaPlaybackItem> LoadSourceFromUriAsync(Uri uri, HttpClient httpClient = null) { UnregisterHandlers(mediaPlayerElement.MediaPlayer); if (tokenMethod == AzureKeyAcquisitionMethod.AuthorizationHeader) { if (ContentSelectorControl.SelectedModel == null) { return(null); } // Use an IHttpFilter to identify key request URIs and insert an Authorization header with the Bearer token. var baseProtocolFilter = new HttpBaseProtocolFilter(); baseProtocolFilter.CacheControl.WriteBehavior = HttpCacheWriteBehavior.NoCache; // Always set WriteBehavior = NoCache httpClientFilter = new AddAuthorizationHeaderFilter(baseProtocolFilter); httpClientFilter.AuthorizationHeader = new HttpCredentialsHeaderValue("Bearer", ContentSelectorControl.SelectedModel.AesToken); httpClient = new HttpClient(httpClientFilter); // Here is where you can add any required custom CDN headers. httpClient.DefaultRequestHeaders.Append("X-HeaderKey", "HeaderValue"); // NOTE: It is not recommended to set Authorization headers needed for key request on the // default headers of the HttpClient, as these will also be used on non-HTTPS calls // for media segments and manifests -- and thus will be easily visible. } AdaptiveMediaSourceCreationResult result = null; if (httpClient != null) { result = await AdaptiveMediaSource.CreateFromUriAsync(uri, httpClient); } else { result = await AdaptiveMediaSource.CreateFromUriAsync(uri); } MediaSource source; if (result.Status == AdaptiveMediaSourceCreationStatus.Success) { adaptiveMediaSource = result.MediaSource; // We use a helper class that logs all the events for the AdaptiveMediaSource: adaptiveMediaSourceLogger = new AdaptiveMediaSourceLogger(LoggerControl, adaptiveMediaSource); // In addition to logging, we use the callbacks to update some UI elements in this scenario: RegisterForAdaptiveMediaSourceEvents(adaptiveMediaSource); // At this point, we have read the manifest of the media source, and all bitrates are known. // Now that we have bitrates, attempt to cap them based on HdcpProtection. HdcpProtection?protection = hdcpSession.GetEffectiveProtection(); SetMaxBitrateForProtectionLevel(protection, adaptiveMediaSource); source = MediaSource.CreateFromAdaptiveMediaSource(adaptiveMediaSource); } else { Log($"Error creating the AdaptiveMediaSource. Status: {result.Status}, ExtendedError.Message: {result.ExtendedError.Message}, ExtendedError.HResult: {result.ExtendedError.HResult.ToString("X8")}"); return(null); } // We use a helper class that logs all the events for the MediaSource: mediaSourceLogger = new MediaSourceLogger(LoggerControl, source); // Save the original Uri. source.CustomProperties["uri"] = uri.ToString(); // You're likely to put a content tracking id into the CustomProperties. source.CustomProperties["contentId"] = Guid.NewGuid().ToString(); var mpItem = new MediaPlaybackItem(source); // We use a helper class that logs all the events for the MediaPlaybackItem: mediaPlaybackItemLogger = new MediaPlaybackItemLogger(LoggerControl, mpItem); HideDescriptionOnSmallScreen(); return(mpItem); }