使用 MediaElement 从 Stream 播放视频 [英] Using MediaElement to play video from Stream
问题描述
是否可以使用 WPF MediaElement 从 System.IO.Stream 对象播放流视频?正在从存储媒体文件的 WCF 服务中检索 Stream 对象.
Is it possible to use the WPF MediaElement to play streaming video from a System.IO.Stream object? The Stream object is being retrieved from a WCF service that stores the media files.
推荐答案
如果您可以让 WCF 通过 http-URL (GET)
交付媒体对象,那么您只需将该 URL 分配给MediaElement.Source
属性 - 参见 http://msdn.microsoft.com/en-us/library/system.windows.controls.mediaelement.source.aspx.
IF you can make the WCF deliver the Media Object via a http-URL (GET)
then you can just assign that URL to the MediaElement.Source
property - see http://msdn.microsoft.com/en-us/library/system.windows.controls.mediaelement.source.aspx.
对于此类 URL 不可用/不可能的情况:
For cases where such URL is not available/possible:
目前无法分配流 - 尽管有一些技巧可以实现这一点,对于基于 DirectShow 的示例,请参见 http://social.msdn.microsoft.com/forums/en-US/wpf/thread/6191ef1a-0010-4294-a5b4-451bbadca33a//a> 和 http://jmorrill.hjtcentral.com/主页/tabid/428/EntryId/15/WPF-Hackery-Part-I.aspx .
Assigning a Stream is currently not possible - although there are some hacks to make that happen, for a DirectShow-based example see http://social.msdn.microsoft.com/forums/en-US/wpf/thread/6191ef1a-0010-4294-a5b4-451bbadca33a/ and http://jmorrill.hjtcentral.com/Home/tabid/428/EntryId/15/WPF-Hackery-Part-I.aspx .
另一种选择是以某种方式托管 Silverlight MediaElement
并使用 SetSource
方法,该方法可以获取流并播放它...参见 http://silverlightviewport.codeplex.com/SourceControl/list/changesets 和 http://msdn.microsoft.com/en-us/library/cc190669%28v=vs.95%29.aspx
Another option would be to somehow host the Silverlight MediaElement
and use the SetSource
method which can take a stream and play it... see http://silverlightviewport.codeplex.com/SourceControl/list/changesets and http://msdn.microsoft.com/en-us/library/cc190669%28v=vs.95%29.aspx
这篇关于使用 MediaElement 从 Stream 播放视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!