This project is read-only.

Adding support for plain text closed captions

Included with the source code is an optional plugin that serves as a proof of concept for building your own closed captioning plugin to displaying plain text captions stored as timeline markers. For more sophisticated or out of the box captioning with formatting support, you should use the TimedText plugin that ships with the player framework.

To use the plain text plugin that ships with the source code:

1. Follow the instructions above to create a new app that uses the Microsoft Media Platform Player Framework for Xaml.

2. Install the Visual Studio Extension SDK for Plain text captions (Microsoft.PlayerFramework.Xaml.CaptionMarkers.vsix) by double clicking on the file.

3. Add 'Microsoft Media Platform: Player Framework Plain Text Captions Plugin' to your project references. Under References --> Windows --> Extensions
captions-step-1.png

4. Set IsCaptionsActive="True" on the player framework object and add the CaptionsPlugin to the Plugins collection.
xmlns:captions="using:Microsoft.PlayerFramework.CaptionMarkers"

<mmppf:MediaPlayer x:Name="pf" Source="http://smf.blob.core.windows.net/samples/videos/wildlife.mp4" IsCaptionsActive="True">
    <mmppf:MediaPlayer.Plugins>
        <captions:CaptionsPlugin/>
    </mmppf:MediaPlayer.Plugins>
</mmppf:MediaPlayer>

5. In the Loaded event of your page, add code to populate the Markers collection with TimelineMarker objects containing captions.
void CaptionsPage_Loaded(object sender, RoutedEventArgs e)
{
    pf.Markers.Add(new Windows.UI.Xaml.Media.TimelineMarker() { Type = CaptionsPlugin.DefaultCaptionMarkerType, Text = "Hello World", Time = TimeSpan.FromSeconds(2) });
    pf.Markers.Add(new Windows.UI.Xaml.Media.TimelineMarker() { Type = CaptionsPlugin.DefaultCaptionMarkerType, Text = "Hello Mars", Time = TimeSpan.FromSeconds(2.5) });
    pf.Markers.Add(new Windows.UI.Xaml.Media.TimelineMarker() { Type = CaptionsPlugin.DefaultCaptionMarkerType, Text = "What a strange conversation!", Time = TimeSpan.FromSeconds(4.5) });
    pf.Markers.Add(new Windows.UI.Xaml.Media.TimelineMarker() { Type = CaptionsPlugin.DefaultCaptionMarkerType, Text = "It must have written by a programmer.", Time = TimeSpan.FromSeconds(10) });            
}

That's all you need to display plain text captions in your app.

Last edited Nov 11, 2012 at 5:38 PM by timgreenfield, version 4