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); }
protected override void OnNavigatedTo(NavigationEventArgs e) { // Create the playback item var source = MediaSource.CreateFromUri(rootPage.CaptionedMediaUri); msLogger = new MediaSourceLogger(LoggerControl, source); var playbackItem = new MediaPlaybackItem(source); mpiLogger = new MediaPlaybackItemLogger(LoggerControl, playbackItem); // Turn on English captions by default playbackItem.TimedMetadataTracksChanged += (item, args) => { if (args.CollectionChange == CollectionChange.ItemInserted) { LoggerControl.Log($"TimedMetadataTracksChanged, Number of tracks: {item.TimedMetadataTracks.Count}"); uint changedTrackIndex = args.Index; TimedMetadataTrack changedTrack = playbackItem.TimedMetadataTracks[(int)changedTrackIndex]; if (changedTrack.Language == "en") { playbackItem.TimedMetadataTracks.SetPresentationMode(changedTrackIndex, TimedMetadataTrackPresentationMode.PlatformPresented); } } }; // Set the source to begin playback of the item this.mediaPlayerElement.Source = playbackItem; LoggerControl.Log($"Loaded: {rootPage.CaptionedMediaUri}"); }
protected override void OnNavigatedFrom(NavigationEventArgs e) { msLogger?.Dispose(); msLogger = null; mpiLogger?.Dispose(); mpiLogger = null; MediaPlayerHelper.CleanUpMediaPlayerSource(mediaPlayerElement.MediaPlayer); }
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); }
protected override void OnNavigatedTo(NavigationEventArgs e) { // Create the media source and supplement with external timed text sources. var source = MediaSource.CreateFromUri(rootPage.UncaptionedMediaUri); msLogger = new MediaSourceLogger(LoggerControl, source); var ttsEnUri = new Uri("ms-appx:///Assets/Media/ElephantsDream-Clip-SRT_en.srt"); var ttsEn = TimedTextSource.CreateFromUri(ttsEnUri); ttsMap[ttsEn] = ttsEnUri; var ttsPtUri = new Uri("ms-appx:///Assets/Media/ElephantsDream-Clip-SRT_pt.srt"); var ttsPt = TimedTextSource.CreateFromUri(ttsPtUri); ttsMap[ttsPt] = ttsPtUri; var ttsSvUri = new Uri("ms-appx:///Assets/Media/ElephantsDream-Clip-SRT_sv.srt"); var ttsSv = TimedTextSource.CreateFromUri(ttsSvUri); ttsMap[ttsSv] = ttsSvUri; ttsEn.Resolved += Tts_Resolved; ttsPt.Resolved += Tts_Resolved; ttsSv.Resolved += Tts_Resolved; source.ExternalTimedTextSources.Add(ttsEn); source.ExternalTimedTextSources.Add(ttsPt); source.ExternalTimedTextSources.Add(ttsSv); // Create the playback item from the source var playbackItem = new MediaPlaybackItem(source); mpiLogger = new MediaPlaybackItemLogger(LoggerControl, playbackItem); // Present the first track playbackItem.TimedMetadataTracksChanged += (item, args) => { LoggerControl.Log($"TimedMetadataTracksChanged, Number of tracks: {item.TimedMetadataTracks.Count}"); playbackItem.TimedMetadataTracks.SetPresentationMode(0, TimedMetadataTrackPresentationMode.PlatformPresented); }; // Set the source to start playback of the item this.mediaPlayerElement.Source = playbackItem; LoggerControl.Log($"Loaded: {rootPage.UncaptionedMediaUri}"); }
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); }