WPF media element, source with https fails
Has anyone seen the following?
I used a MediaElement in a C# WPF project. I tried to access a video on a secure SharePoint site (NTLM), I set the Source to a https address and the video playback fails.
var u = new Uri(@"https://www......com/WindowsMedia.wmv", UriKind.Absolute);
mediaElement.Source = u;
mediaElement.Play();
When开发者_运维百科 trying to play the video I get an exception:
Object reference not set to an instance of an object.
I hope someone has seen this before and can give me a hint. Unfortunately I am not able to share the secure video location.
I'll start out by saying I have zero experience with Share Point but... Perhaps you will need to download the file locally first since it is over HTTPS and MediaElement doesn't seem to have any methods for authenticating.
So download file to local disk:
using System;
using System.IO;
using System.Net;
WebClient webClient = new WebClient();
webClient.Credentials = new NetworkCredential("username", "password", "domain");
webClient.DownloadFile("https://servername/path/documentToDownload.txt", "localPathToSaveFile");
And then set MediaElement.Source = "localPathToSaveFile"
精彩评论