通过 Windows Media Player 在 C# 应用程序中播放视频。有没有稳定、性能良好的解决方案?

发布于 2024-09-18 01:54:54 字数 970 浏览 2 评论 0原文

我编写了一个具有 2 个窗口的 WPF 应用程序(使用 Visual C# 2010 Express)。第一个有各种按钮,另一个使用 MediaElement 控件显示视频。按下按钮时,将播放与其关联的视频,如果该视频已在播放,则将停止该视频。

在我的开发机器上(Windows 7、良好的显卡、大量内存等),它运行良好。我遇到的唯一问题是,当连接到调试器时,它非常不稳定,但是当正常运行时,这些问题就会消失。

不幸的是,当在性能低得多的 XP 机器上运行时,视频的运行速度为 1-2 fps。尽管视频在 Windows Media Player 中运行良好,但仍然如此。

似乎有很多关于 MediaElement 控件性能不佳的报告(更不用说它可以播放的内容不一致),因此我决定考虑一些替代方案。

我尝试了一个免费的库调用 WPF MediaKit (http://wpfmediakit.codeplex.com),我认为它可能有一些效果,然而,当我让它在 XP 机器上工作时,它坚决拒绝在我的开发机器上显示视频,尽管使用完全相同的代码。我仍然希望我能做到这一点,但我不相信它会有所帮助,因为它仍在幕后使用 MediaElement 控件。

然后,我尝试使用 wmp.dll COM 控件(Windows 窗体而不是 WPF),甚至使用最简单的应用程序(新的 Windows 窗体项目、添加到窗体中的 WMP 控件以及用于在加载时设置 URL 的 1 行代码),我也会得到奇怪的行为。连接调试器后,它可以在多个显示器上运行,但有时当它开始播放时,它只是在第一几帧上反复出现卡顿,摆脱这种情况的唯一方法似乎是将其移动到另一个显示器。如果我不使用调试器,我似乎没有遇到卡顿问题,但视频仅显示在主监视器上,一旦我将窗口移动到辅助监视器,它就会变黑。

所以我的问题是有人经历过类似上述的事情和/或有一个不错的解决方案吗?如果能找到在附加和不附加调试器的情况下都能一致工作的东西,那就太好了!

I've written a WPF application (in Visual C# 2010 Express) that has 2 windows. The 1st has a various buttons, the other displays video using the MediaElement control. When a button is pressed, a video associated with it is played or stopped if it's already playing.

On my development machine (Windows 7, good graphics card, lots of memory etc), this runs fine. The only problem I've encountered is that when attached to the debugger it is very unstable but when run normally these issues go away.

Unfortunately when run on a much less powerful XP machine the videos run at 1-2fps. This is despite the fact that the videos run fine in Windows Media Player.

There seem to quite a lot of reports of poor performance for the MediaElement control (not to mention inconsistencies in what it can play) so I decided to look at some alternatives.

I tried a free library call WPF MediaKit (http://wpfmediakit.codeplex.com) that I thought might have some effect, however while I've got it to work on an XP machine, it resolutely refuses to display videos on my development machine despite using exactly the same code. I'm still hoping I can this to work but I'm not confident it will help given it's still using the MediaElement control behind the scenes.

I then tried using wmp.dll COM control (Windows forms rather than WPF) and even with the simplest app (new Windows Form project, WMP control added to form, and 1 line of code to set the URL on load) I get odd behaviour. With the debugger attached, it works across multiple monitors, but sometimes when it starts playing, it just repeatedly stutters over the 1st few frames and the only way to break it out of this seems to be to move it to the other monitor. If I'm not using the debugger, I don't seem to get the stutter issue but the video is only displayed on the main monitor, as soon as I move the window to the secondary monitor, it goes black.

So my question is has anyone experienced anything like the above and/or have a decent solution to it? It would be especially nice to find something that works consistently with and without the debugger attached!

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

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

发布评论

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

评论(2

Bonjour°[大白 2024-09-25 01:54:59

WPF MediaKit 不在幕后使用 MediaElement,而是使用 D3DImage 互操作类向 WPF 提供高性能视频。

XP 中的 WPF 在性能方面一直是时好时坏。您可能需要查看渲染层以确保 WPF 完全硬件加速。还要确保您拥有最新的可用视频驱动程序并且 GPU 具有功能。

-杰尔

WPF MediaKit does not use MediaElement behind the scenes, but instead uses the D3DImage interop class to provide high performance video to WPF.

WPF in XP has always been a hit-or-miss in terms of performance. You might want to take a look at the rendering tier to ensure WPF is fully hardware accelerating. Also make sure you have the newest video drivers available and that the GPU is capable.

-Jer

梦冥 2024-09-25 01:54:57

你尝试过这个库吗?

http://directshownet.sourceforge.net/about.html

还有这个 .NET 接口VideoLAN 媒体播放器,但这引入了对 VLC 的依赖:

http://wiki.videolan.org/.Net_Interface_to_VLC< /a>

Have you tried this library?

http://directshownet.sourceforge.net/about.html

There's also this .NET interface to VideoLAN media player, but that introduces a dependency to VLC:

http://wiki.videolan.org/.Net_Interface_to_VLC

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