【发布时间】:2011-01-25 02:22:46
【问题描述】:
我正在尝试使用 MediaElement 让视频永远重复。我在http://msdn.microsoft.com/en-us/library/ms741866.aspx 找到了下面的代码,它工作正常。
<!-- The MediaElement control plays the sound. -->
<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="C:\MyVideo1.wmv" Storyboard.TargetName="myMediaElement"
RepeatBehavior="Forever" />
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</MediaElement.Triggers>
</MediaElement>
我遇到的问题是,当我尝试将 MediaTimeLine 绑定到 xml 源时,我收到错误 - “必须指定 URI”。
<MediaTimeline Source="{Binding XPath=MyVideos}"
Storyboard.TargetName="myMediaElement" RepeatBehavior="Forever" />
是否有可以替代 xaml 的 C# 解决方案?
【问题讨论】:
-
我删除了触发器和 MediaTimeLine 并为“myMediaElement”创建了一个 xpath 绑定源。然后我将此代码添加到 myMediaElement_MediaEnded: this.myMediaElement.Position = TimeSpan.FromSeconds(0); this.myMediaElement.Play();它可以工作,但由于某种原因加载缓慢
-
我也想知道如何使用 XAML 做到这一点。问题似乎是 Source 需要一个 URI,而不是字符串。不过,绑定到字符串并自动将其转换为 URI 似乎有点棘手,如下所示:stackoverflow.com/questions/20586/…
-
我的名声中有 50 个问题仍未得到解答。 :(
标签: c# wpf mediaelement