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 (2)

  1. Thor says:

    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

  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.