C# 当wpf MediaElement的源是https uri时,如何使其播放
在wpf独立应用程序(.exe)中,我在主窗口中包含了一个MediaElementC# 当wpf MediaElement的源是https uri时,如何使其播放,c#,wpf,nullreferenceexception,mediaelement,C#,Wpf,Nullreferenceexception,Mediaelement,在wpf独立应用程序(.exe)中,我在主窗口中包含了一个MediaElement <Window x:Class="Media.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Main Window" Heigh
<Window x:Class="Media.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Main Window" Height="350" Width="525">
<Grid>
<MediaElement x:Name="Player" Stretch="Uniform" LoadedBehavior="Manual" UnloadedBehavior="Stop"/>
</Grid>
</Window>
调用Play()
方法时,将抛出NullReferenceException
,而不是播放媒体内容MediaElement
被初始化,从Play()
方法抛出NullReferenceException
,如下所示
可以在Windows Media Player中打开视频的相同Uri(文件->打开Url)
问题似乎出在MediaPlayerState.OpenMedia
方法(MediaElement内部使用的对象)中,该方法试图检查从SecurityHelper.ExtractUriForClickOnceDeployedApp
检索的appDeploymentUri是否具有HTTPS方案。应用程序没有使用ClickOnce
(它有一个独立的安装程序)部署,并且appDeploymentUri为空,因此出现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组件都有更多的bug。它不仅有bug,而且缺少Silverlight所具有的许多特性。HTTPS与Silverlight一起工作 我浏览了代码,但没有找到修改的方法。也许有一些疯狂的反射黑客可以让你这么做,但那是黑客,我不推荐这样做。顺便说一句,这似乎是一个真正的错误,也许让微软的人知道它
最简单的解决方案是使用OWIN创建“内存Web服务器”。然后您可以通过
http://localhost:1337
并包装底层https://内容。尽管如此,https内容仍然是安全的,因为您是从“内存Web服务器”流式传输它,并且从未发出过“真正的”Web请求。它仍然应该是高效和安全的。谢谢,我做到了:。看看会发生什么。您的想法很有趣,如果我们无法解决服务器上的问题,我们可以尝试此方法。@Erti Chris Eelmaa,您能否附上一些OWIN用于“包装底层https://内容”的示例源代码?您好,您找到解决方案了吗?也许你能解释一下如何制作一个“内存Web服务器”来获取http url吗?我今天也发现了一个奇怪而丑陋的错误。你是否在MS上更新投票并重新报告了你的问题。如果你将链接添加到错误报告中,我将更新投票。这实际上是你自己的错误报告。您已将其张贴在已接受答案的评论中。;-)仅供参考,既然WPF是开源的,我记录了一个bug,并计划很快修复它:
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))