Search code examples
xamluwpmedia-player

How to set specified TimedTextSource as default?


I'm using MediaPlayElement, and I have set the media source. Now I want to add several Closed Captions, such English, Indo, Simplified Chinese.

I use the following code to add TimedTextSource, and they are all placed in the media player, but how to specify an item as turned on when opening a media?

var timedTextSource = TimedTextSource.CreateFromUri(new Uri(item.url), item.name);
mediaSource.ExternalTimedTextSources.Add(timedTextSource);

enter image description here


Solution

  • You can try using TimedMetadataTracks.SetPresentationMode like this:

    // ms: An instance of MediaSource
    // mplayer: MediaPlayerElement
    // this code is after add the TimedTextSource
    
    var playbackItem = new MediaPlaybackItem(ms);
    var player = new MediaPlayer();
    player.Source = playbackItem;
    player.BufferingStarted += (_s, _e) =>
    {
        playbackItem.TimedMetadataTracks.SetPresentationMode(0, TimedMetadataTrackPresentationMode.PlatformPresented);
    };
    mplayer.SetMediaPlayer(player);
    

    This method is to actively switch the text track when the video starts to buffer.

    Best regards.