在 MediaElement 中重复视频的最简单方法是什么

发布于 2024-09-13 01:17:44 字数 263 浏览 4 评论 0原文

我有一个 MediaElement,其中源绑定到一些数据

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

重复视频的最简单方法是什么?理想情况下,MediaElement 将具有重复行为属性。

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

但我找不到这样的财产。

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

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

What is the simplest way to have the video repeat? Ideally, MediaElement would have a repeat behavior property.

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

But I can't find such a property.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

治碍 2024-09-20 01:17:44

您需要将 Storyboard 添加到 MediaElement。请参阅下面的示例:

<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>

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>
公布 2024-09-20 01:17:44

我通过设置 <代码>UnloadedBehaviorMediaState.Manual 和以下代码:

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

将位置设置为零不起作用...

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...

海未深 2024-09-20 01:17:44

我知道有点晚了,但我无法使用 MSDN 上的示例。因此,经过研究,我找到了这个项目:WPF Media Kit,只需单击浏览屏幕右侧最新版本中的链接。您将输入示例应用程序的代码。我喜欢这个库,因为循环就像:

MediaUriElement MyPlayer.Loop = True;


希望这对其他人有帮助。

问候!

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!

み格子的夏天 2024-09-20 01:17:44

mediaElement.Position = new TimeSpan(0,0,1) 添加到媒体播放器方法(在播放媒体之前)不会产生任何效果,正如 MasterMastic 和 Guido Zanon 所建议的那样。我使用给定的内容为 MediaEnded 创建了 MediaElement 事件,并且它有效。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文