wpf 使用 MediaElement 从 UDP/RTSP 播放视频?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31415161/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Play video from UDP/RTSP using MediaElement?
提问by chelsea
Is it possible to play videos streamed from UDP/RTSP using WPF's MediaElement control? During my testing, I have attempted to pass a URI containing a UDP stream to the MediaElement player, but when I launch my application, the media player is blank as though there is no media source. Here is my sample code:
是否可以使用 WPF 的 MediaElement 控件播放从 UDP/RTSP 流式传输的视频?在测试期间,我尝试将包含 UDP 流的 URI 传递给 MediaElement 播放器,但是当我启动我的应用程序时,媒体播放器是空白的,就好像没有媒体源一样。这是我的示例代码:
MainWindow.xaml.cs:
主窗口.xaml.cs:
public partial class MainWindow: Window
{
public MainWindow()
{
InitializeComponent();
VideoMediaElement.Source = new Uri("udp:\\@12.3.4.567:890");
VideoMediaElement.Play();
}
}
MainWindow.xaml:
主窗口.xaml:
<Window x:Class="MyApplication.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="300" Width="300">
<Grid>
<MediaElement Margin="5,5,5,5" Grid.Row="1" x:Name="VideoMediaElement" LoadedBehavior="Manual" />
</Grid>
Is there something obvious that I'm missing here? I have tested this setup using a video that is stored on my file system, and it plays with no problems - it's just the streaming that doesn't want to work.
有什么明显的东西我在这里失踪了吗?我已经使用存储在我的文件系统上的视频测试了这个设置,并且它播放没有问题——它只是不想工作的流媒体。
If this is not possible using MediaElement, I am open to suggestions for controls that I can use instead. However, I need a control that is purely WPF and does not rely on any WinForms interop. Any suggestions are appreciated.
如果使用 MediaElement 无法做到这一点,我愿意接受我可以使用的控件建议。但是,我需要一个纯粹是 WPF 并且不依赖于任何 WinForms 互操作的控件。任何建议表示赞赏。
UPDATE: After creating a handler for the "MediaFailed" event, I was able to receive this error: "Media file download failed" with an inner exception of System.Runtime.InteropServices.COMException with HResult 0xC00D0FEA. I referenced this: MediaPlayer cannot play file names without an extensionand attempted to make some changes to the registry, but they don't seem to be fixing the problem. Again, any suggestions are appreciated. I'll continue to update this thread as I get more information.
更新:为“MediaFailed”事件创建处理程序后,我能够收到此错误:“媒体文件下载失败”,内部异常为 System.Runtime.InteropServices.COMException,HResult 为 0xC00D0FEA。我引用了这个:MediaPlayer 不能在没有扩展名的情况下播放文件名并尝试对注册表进行一些更改,但他们似乎没有解决问题。再次,任何建议表示赞赏。当我获得更多信息时,我会继续更新这个线程。
采纳答案by chelsea
After A LOT of research, it seems that what I am attempting to do may not be possible. The WPF MediaElement control (and Windows Media Player) appear to support playing videos over a network, but not from a stream. See the following thread on MSDN: https://social.msdn.microsoft.com/Forums/vstudio/en-US/e90b7e73-62b2-40b2-a725-4b60e02d65a1/play-video-stream-in-wpf?forum=wpf
经过大量研究,似乎我试图做的事情可能是不可能的。WPF MediaElement 控件(和 Windows Media Player)似乎支持通过网络播放视频,但不支持从流播放视频。请参阅 MSDN 上的以下主题:https: //social.msdn.microsoft.com/Forums/vstudio/en-US/e90b7e73-62b2-40b2-a725-4b60e02d65a1/play-video-stream-in-wpf?forum =wpf
I'm still on the lookout for a WPF control that will play video from a stream, but I haven't found anything.
我仍在寻找可以从流中播放视频的 WPF 控件,但我什么也没找到。

