Share via


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;
me.Clock.Controller.Begin();
}

void me_MediaEnded(object sender, RoutedEventArgs e)
{
me.Clock.Controller.Begin();
}

Comments

  • Anonymous
    March 01, 2006
    Hi

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

    http://blog.rioterdecker.net/blogs/chaz/archive/2005/11/30/41.aspx

    Cool post btw

    Rgds,
    Thor
  • Anonymous
    March 07, 2006
    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.