在 wpf 独立应用程序 (.exe) 中,我在 MainWindow 中包含了一个 MediaElement
In a wpf standalone application (.exe) I have included a MediaElement in the MainWindow
<Window x:Class="Media.MainWindow" xmlns="schemas.microsoft/winfx/2006/xaml/presentation" xmlns:x="schemas.microsoft/winfx/2006/xaml" Title="Main Window" Height="350" Width="525"> <Grid> <MediaElement x:Name="Player" Stretch="Uniform" LoadedBehavior="Manual" UnloadedBehavior="Stop"/> </Grid> </Window>从后面的代码中,我将其 Source 设置为任何 https Uri:
and from the code behind I set its Source to any https Uri:
public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); var source = new Uri("stream_which_can_be_opened_with_windows_media_player", UriKind.Absolute); Player.Source = source; Player.Play(); } }当 Play() 方法被调用时,会抛出一个 NullReferenceException 而不是播放媒体内容.MediaElement 被初始化,NullReferenceException 从 Play() 方法抛出,见下文.
When the Play() method is called a NullReferenceException is thrown instead of playing the media content. MediaElement is initialized, the NullReferenceException is thrown from the Play() method, see below.
可以在 Windows Media Player 中打开视频的相同 Uri(文件->打开 Url).
The same Uri for the video can be opened in Windows Media Player (File->Open Url).
问题似乎出在 MediaPlayerState.OpenMedia 方法(MediaElement 内部使用的对象)中,该方法试图检查 appDeploymentUri 是否从 SecurityHelper.ExtractUriForClickOnceDeployedApp 检索 具有 HTTPS 方案.应用程序未使用 ClickOnce 部署(它有一个独立的安装程序)并且 appDeploymentUri 为 null,因此 NullReferenceException.
The issue seems to be in MediaPlayerState.OpenMedia method (an object which the MediaElement uses internally) which tries to check if appDeploymentUri retrieved from SecurityHelper.ExtractUriForClickOnceDeployedApp has the scheme HTTPS. The application is not deployed with ClickOnce (it has a standalone installer) and the appDeploymentUri is null, hence the NullReferenceException.
这是来自 PresentationFramework.dll、System.Windows.Media.MediaPlayerState.OpenMedia
This is from 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))有没有人有任何解决方法/解决方案使其工作?
Does anyone have any about a workaround/solution to make it work?
推荐答案我使用 MediaElement 的次数已经不少了,老实说,我可以说这是一团糟,比我遇到的任何其他 WPF 组件都有更多的错误.它不仅有缺陷,而且缺少 Silverlight 的许多功能.HTTPS 适用于 Silverlight.
I have been working with MediaElement quite few times, and I can honestly say it's a piece of shit and has more bugs than any other WPF component I've encountered. Not only has it bugs, but it's lacking a lot of features that Silverlight has. HTTPS works with Silverlight.
我浏览了代码,但没有看到更改它的方法.也许有一些 MAD 反射黑客可以让你这样做,但那是黑客,我不建议这样做.Ps,这好像是一个真正的bug,也许让微软的人知道吧.
I went through code and I did not see the way to change it. Perhaps there is some MAD reflection hack which would allow you to do it, but that's hacking and I don't recommend that. Ps, it seems like a genuine bug, perhaps let the Microsoft guys know about it.
最简单的解决方案是使用 OWIN 制作内存网络服务器".然后,您可以通过 localhost:1337 流式传输并包装底层 内容.不过,https 内容仍然是安全的,因为您是从内存网络服务器"流式传输它,并且从未发出过真实"的网络请求.它应该仍然是有效的&安全.
The easiest solution would be to make a "memory webserver" using OWIN. You can then stream through localhost:1337 and wrap the underlying content. The https content would still be safe though, since you are streaming it from "memory webserver" and no "real" webrequests are ever made. It should still be efficient & secure.
更多推荐
当源是 https uri 时,如何使 wpf MediaElement 播放
发布评论