Looping Video in the February CTP

To get media files looping in the February CTP, you need to wire up a media timeline and manually catch the media_ended event, using the Controller to start the video again.  The RepeatBehavior property does not seem to work.  Assume you have some XAML like this:

<Button Click="play" Width="100" Height="100">play</Button>
<MediaElement Name="me" Width="100" Height="100"/>

To play and have the media loop, do this:

private void play(object sender, EventArgs e)
    MediaTimeline mt = new MediaTimeline(new Uri("mymedia.wmv", UriKind.Relative));
    MediaClock mc = mt.CreateClock();
    me.MediaEnded += new RoutedEventHandler(me_MediaEnded);
    me.Clock = mc;

void me_MediaEnded(object sender, RoutedEventArgs e)




Comments (2)

  1. Thor says:


    Here is my buddy’s post about playing mediaelements, it covers pretty much the same thing as you do


    Cool post btw



  2. karstenj says:

    Yeah, the only problem is that the methodology he uses for the November CTP is broken in the Feb CTP, thus the workaround posted above.

Skip to main content