In a wpf standalone application (.exe) I have included a MediaElement in the MainWindow
<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>
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("https://stream_which_can_be_opened_with_windows_media_player.com", UriKind.Absolute);
Player.Source = source;
Player.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.
The same Uri for the video can be opened in Windows Media Player (File->Open Url).
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
.
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?