I'm trying to play HLS stream in Windows 10 UWP app. This stream contains embedded captions that can be turned on in VLC player or in Edge browser when playing the HLS stream directly.
Is there a way how to show these embedded captions in UWP MediaElement as well?
I've tried using this approach but no textSources are loaded or shown when using these steps:
Uri source = new Uri("http://nasatv-lh.akamaihd.net/i/NASA_101@319270/master.m3u8");
AdaptiveMediaSourceCreationResult result = await AdaptiveMediaSource.CreateFromUriAsync(source);
if (result.Status == AdaptiveMediaSourceCreationStatus.Success)
{
AdaptiveMediaSource astream = result.MediaSource;
MediaSource mediaSource = MediaSource.CreateFromAdaptiveMediaSource(astream);
var metadataTracks = mediaSource.ExternalTimedMetadataTracks.ToArray();
var textSources = mediaSource.ExternalTimedTextSources.ToArray();
// both arrays above are empty when loading the NASA TV stream
MediaPlaybackItem mediaElement = new MediaPlaybackItem(mediaSource);
Player.SetPlaybackSource(mediaElement);
}
Note I've tried to use the Player Framework as well, but with no success.
How to show these embedded captions in UWP MediaElement?
To show the embedded captions in this stream, you can just set the URI as MediaElement
's Source
and change AreTransportControlsEnabled
property to true
to enable the standard transport controls.
<MediaElement x:Name="mediaElement"
AreTransportControlsEnabled="True"
Source="http://nasatv-lh.akamaihd.net/i/NASA_101@319270/master.m3u8" />
Once it has valid captions, the closed caption menu will show and we can use it to control whether to display closed captions like following:
MediaSource.ExternalTimedMetadataTracks and MediaSource.ExternalTimedTextSources property are used for get external timed metadata tracks or text sources associated with the MediaSource. As the captions in the stream are embedded and you didn't add TimedTextSource in ExternalTimedTextSources
so there is no textSources
.