What is simplest way to repeat a video in a MediaElement

后端 未结 4 1674
-上瘾入骨i
-上瘾入骨i 2020-12-16 21:46

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


What is the simplest way

相关标签:
4条回答
  • 2020-12-16 22:21

    I made it work by setting the UnloadedBehavior to MediaState.Manual and the following code:

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

    Setting the position to Zero didnt work...

    0 讨论(0)
  • 2020-12-16 22:29

    You need to add a Storyboard to the 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>
    
    0 讨论(0)
  • 2020-12-16 22:41

    I know it's a little late, but I couldn't get to work the example from MSDN. So after research I've found this project: WPF Media Kit, just click at the Browse link in the Latest Version at the right side of the screen. You'll enter the code of the sample application. I liked this library because a loop was as simple as:

    MediaUriElement MyPlayer.Loop = True;
    

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

    Hope this helps someone else.

    Regards!

    0 讨论(0)
  • 2020-12-16 22:45

    Adding mediaElement.Position = new TimeSpan(0,0,1) to the media player method doesn't (before playing the media) have any effect rather as suggested by MasterMastic and Guido Zanon. I created MediaElement event for MediaEnded with the given content and it worked.

    0 讨论(0)
提交回复
热议问题