问题描述:

I have a WPF application where I am loading and streaming videos for training purposes. Currently it works when I use an internal server (IIS). However because of the strain it is putting on local resources we are trying to leverage our Azure account, which has CDN services included.

My thought was that I could switch out the url from

source = new Uri(@"http://192.168.1.2/videos/NewCoupons.wmv", UriKind.Absolute);

to

source = new Uri(@"https://myazurespace.blob.core.windows.net/asset-8e1-snip-04%3A25Z", UriKind.Absolute);

I cut the Azure link down ( -snip- ) because it is way to long to be readable and is not relevant for this question. If I cut and past the link into my browser the browser will prompt to play the video so I know the link is good. However when I try to run it from my WPF I get a {"Object reference not set to an instance of an object."} System.NullReferenceException error right on the exception catch below.

private void PlayButton_Click(object sender, RoutedEventArgs e)

{

try

{

if (mediaElement.Source != null)

mediaElement.Play();

}

catch (Exception ex)

{

MessageBox.Show("Error: " + ex.ToString());

}

}

So do I have to do something different in my code to use media from an external CDN? By the way I did cut and paste the link in the exception to the browser to make sure something wasn't getting malformed on its way there and it did pull the video from Azure correctly.

网友答案:

Seems to be a known bug that the WPF team doesn't want to fix. WPF MediaElement throws a NullReferenceException for HTTPS URLs. Your local version should fail too with HTTPS. Since the bug is set to Won't Fix, your best bet might be to just use an HTTP URL. Link to official bug page: connect.microsoft.com/VisualStudio/feedback/details/934355/

Per comments, you'll need to update the URI for your video stream to use HTTP.

相关阅读:
Top