如何在 Windows 10 UWP 应用程序中显示 HLS 流的嵌入式隐藏式字幕?

How to display embedded Closed Captions for HLS stream in Windows 10 UWP app?

我正在尝试在 Windows 10 UWP 应用程序 中播放 HLS 流。 This stream 包含 嵌入式字幕 可以在直接播放 HLS 流时在 VLC 播放器或 Edge 浏览器中打开。

有没有办法在 UWP MediaElement 中也显示这些嵌入式字幕?

我试过使用这种方法,但是在使用这些步骤时没有加载或显示文本源:

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);
}

请注意,我也尝试过使用播放器框架,但没有成功。

How to show these embedded captions in UWP MediaElement?

显示 this stream, you can just set the URI as MediaElement's Source and change AreTransportControlsEnabled propertytrue 中的嵌入字幕以启用标准传输控件。

<MediaElement x:Name="mediaElement"
              AreTransportControlsEnabled="True"
              Source="http://nasatv-lh.akamaihd.net/i/NASA_101@319270/master.m3u8" />

一旦它有有效的字幕,隐藏字幕菜单就会显示出来,我们可以用它来控制是否显示隐藏字幕,如下所示:

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 TimedTextSourceExternalTimedTextSources所以没有textSources