如何在源为https uri时播放wpf MediaElement

在wpf独立应用程序(.exe)中,我在MainWindow中包含了一个MediaElement

     

从后面的代码我将其Source设置为任何https Uri:

 public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); var source = new Uri("https://stream_which_can_be_opened_with_windows_media_player.com", UriKind.Absolute); Player.Source = source; Player.Play(); } } 

调用Play()方法时,抛出NullReferenceException而不是播放媒体内容。 初始化MediaElement ,从Play()方法抛出NullReferenceException ,见下文。

可以在Windows Media Player(文件 – >打开URL)中打开video的相同Uri。

问题似乎在MediaPlayerState.OpenMedia方法( MediaElement内部使用的对象)中,该方法尝试检查从SecurityHelper.ExtractUriForClickOnceDeployedApp检索到的appDeploymentUri是否具有HTTPS方案。 该应用程序未使用ClickOnce部署(它具有独立安装程序)且appDeploymentUri为null,因此为NullReferenceException

这是来自PresentationFramework.dll,System.Windows.Media.MediaPlayerState.OpenMedia

  if (SecurityHelper.AreStringTypesEqual(uriToOpen.Scheme, Uri.UriSchemeHttps)) { // target is HTTPS. Then, elevate ONLY if we are NOT coming from HTTPS (=XDomain HTTPS app to HTTPS media disallowed) //source of the issue Uri appDeploymentUri = SecurityHelper.ExtractUriForClickOnceDeployedApp(); //appDeploymentUri is null if (!SecurityHelper.AreStringTypesEqual(appDeploymentUri.Scheme, Uri.UriSchemeHttps)) 

有没有人有一个解决方法/解决方案,使其工作?

我一直在使用MediaElement很多次,我可以诚实地说这是一个糟糕的错误,并且比我遇到的任何其他WPF组件有更多的错误。 它不仅存在缺陷,而且缺少Silverlight的许多function。 HTTPS适用于Silverlight。

我通过代码,我没有看到改变它的方法。 也许有一些MADreflection黑客会允许你这样做,但这是黑客攻击,我不建议这样做。 Ps,它似乎是一个真正的错误,也许让微软的人知道它。

最简单的解决方案是使用OWIN制作“内存网络服务器”。 然后,您可以通过http://localhost:1337进行流式处理并包装基础的https://内容。 https内容仍然是安全的,因为您从“内存网络服务器”流式传输,并且没有“真正的”网络请求。 它仍然应该是高效和安全的。