The easiest way to repeat a video in MediaElement

I have a MediaElement where the source is bound to some data

<MediaElement Source='{Binding Something}' />

What is the easiest way to repeat a video? Ideally, MediaElement will have the property of repeated behavior.

<MediaElement RepeatBehavior='Forever' ... />

But I can not find such a property.

+5
source share
4 answers

You need to add a storyboard to MediaElement. See the example below:

<MediaElement Name="myMediaElement" >
      <MediaElement.Triggers>
        <EventTrigger RoutedEvent="MediaElement.Loaded">
          <EventTrigger.Actions>
            <BeginStoryboard>
              <Storyboard>

                <!-- The MediaTimeline has a RepeatBehavior="Forever" which makes the media play
                     over and over indefinitely.-->
                <MediaTimeline Source="media\tada.wav" Storyboard.TargetName="myMediaElement"  
                 RepeatBehavior="Forever" />

              </Storyboard>
            </BeginStoryboard>
          </EventTrigger.Actions>
        </EventTrigger>
      </MediaElement.Triggers>
    </MediaElement>
+11
source

I did this by setting UnloadedBehaviorto MediaState. Manualand the following code:

private void mediaElement_OnMediaEnded(object sender, RoutedEventArgs e)
{
    mediaElement.Position = new TimeSpan(0,0,1);
    mediaElement.Play();
}

Setting a position on Zero does not work ...

+6
source

, MSDN. : WPF Media Kit, "" , . , , :

MediaUriElement MyPlayer.Loop = True;

  <DirectShowControls:MediaUriElement x:Name="MyPlayer" Loop="True" />

, - .

!

+3

mediaElement.Position = new TimeSpan(0,0,1) ( ) , MasterMastic Guido Zanon. MediaElement MediaEnded , .

0

All Articles