简体   繁体   English

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

[英]Playing videos in C# application via Windows Media Player. Is there a stable, decently performing solution?

I've written a WPF application (in Visual C# 2010 Express) that has 2 windows. 我已经编写了一个具有2个窗口的WPF应用程序(在Visual C#2010 Express中)。 The 1st has a various buttons, the other displays video using the MediaElement control. 第一个按钮具有各种按钮,另一个按钮使用MediaElement控件显示视频。 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. 在我的开发机器(Windows 7,良好的图形卡,大量内存等)上,此程序运行良好。 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. 不幸的是,当在功能不那么强大的XP计算机上运行时,视频以1-2fps的速度运行。 This is despite the fact that the videos run fine in Windows Media Player. 尽管视频在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. 关于MediaElement控件的性能似乎很差的报道很多(更不用说它可以播放的不一致)了,所以我决定考虑一些替代方案。

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. 我尝试了一个免费的库调用WPF MediaKit( http://wpfmediakit.codeplex.com ),我认为这可能会产生一些效果,但是尽管我可以在XP计算机上运行它,但它坚决拒绝在我的开发中显示视频机器,尽管使用完全相同的代码。 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. 我仍然希望我能做到这一点,但我不确定它会在后台使用MediaElement控件,但对它会有帮助。

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. 然后,我尝试使用wmp.dll COM控件(Windows窗体而不是WPF),甚至使用最简单的应用程序(新的Windows Form项目,将WMP控件添加到窗体,以及1行代码来设置加载时的URL)时,我都遇到了奇怪的问题。 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. 附加了调试器后,它可以在多个监视器上工作,但是有时在开始播放时,它反复在第1帧中停顿,打破这种情况的唯一方法似乎是将其移至另一台监视器。 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! 找到在没有调试器的情况下都能正常工作的东西会特别好!

Have you tried this library? 您尝试过这个图书馆吗?

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

There's also this .NET interface to VideoLAN media player, but that introduces a dependency to VLC: VideoLAN媒体播放器也有此.NET接口,但这为VLC引入了依赖性:

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

WPF MediaKit does not use MediaElement behind the scenes, but instead uses the D3DImage interop class to provide high performance video to WPF. WPF MediaKit不在幕后使用MediaElement,而是使用D3DImage互操作类向WPF提供高性能的视频。

WPF in XP has always been a hit-or-miss in terms of performance. 在性能方面,XP中的WPF一直是命中注定的。 You might want to take a look at the rendering tier to ensure WPF is fully hardware accelerating. 您可能需要看一下渲染层,以确保WPF能够完全加速硬件。 Also make sure you have the newest video drivers available and that the GPU is capable. 另外,请确保您拥有最新的视频驱动程序,并且具备GPU的功能。

-Jer -杰尔

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM