如何使用 WPF 中的 MediaElement 将视频从一个位置循环播放到另一个位置

发布于 2024-12-29 03:18:13 字数 97 浏览 5 评论 0原文

我正在使用 WPF mediaelement 来播放视频。我需要的是从 x 位置到 y 位置循环播放视频。有没有办法在不使用计时器和轮询 Position 属性的情况下实现此目的?

I am using WPF mediaelement for playing video. What I need is to cyclically play a video form x position to y position. Is there any way to achieve this without using timer and polling Position property?

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

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

发布评论

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

评论(1

慈悲佛祖 2025-01-05 03:18:13

您不必轮询位置属性,但可以将其设置为从开始位置开始播放,启动计时器并设置时间差的间隔。

TimeSpan startTime = TimeSpan.FromSeconds(45);
TImeSpan endTime = TimeSpan.FromSeconds(55);
int timeDifference = endTime.TotalSeconds - startTime.TotalSeconds;

mediaElement.Position = startTime;

Timer t = new Timer() { Interval = timeDifference * 1000, AutoReset = true };
t.Tick += (sender, e) { mediaElement.Position = startTime };
t.Start();

You don't have to poll the position property, but you can set it to begin play at start position, start a timer and set the interval for the time difference.

TimeSpan startTime = TimeSpan.FromSeconds(45);
TImeSpan endTime = TimeSpan.FromSeconds(55);
int timeDifference = endTime.TotalSeconds - startTime.TotalSeconds;

mediaElement.Position = startTime;

Timer t = new Timer() { Interval = timeDifference * 1000, AutoReset = true };
t.Tick += (sender, e) { mediaElement.Position = startTime };
t.Start();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文