Subtitles in a MediaElement

16 Nov

Loading subtitles to MediaElement in Silverlight is pretty easy but there are some features that you need to be aware of.

You associate a list of subtitles to a MediaElement by adding Markers to the MediaElement.

    x:Name="MyMediaElement" />

    new TimelineMarker()
        Text = "xamlgeek made this subtitle",
        Time = TimeSpan.FromMilliseconds(1000)

To display the subtitle on an UI element like a formatted TextBlock you need to subscribe to the MarkerReached event on the MediaElement. This event will be fired when the media reaches the marked on the specified timespan.

MyMediaElement.MarkerReached += (se, ea) =>
    MySubTitleTextBlock = ea.Marker.Text;

But there is one minor problem that you need to be aware of when building more complex media applications. If you add a TimeLineMarker to a MediaElement before the MediaOpened event is fired, the Markers will not trigger the MarkerReached event.

You can take a look at to see a running media application using subtitles as described above.

by xamlgeek

One Response to “Subtitles in a MediaElement”

  1. Anders February 11, 2012 at 16:06 #

    If you want a 1-month free access to Sputnik – you can get it her:

Leave a Reply to Anders Cancel reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: