9

I am trying to Play video from https site into my media element throwing the following exception.

An exception of type 'System.NullReferenceException' occurred in PresentationCore.dll but was not handled in user code

Additional information: Object reference not set to an instance of an object.

This is my code in xmal

 <MediaElement x:Name="mediaElement" LoadedBehavior="Manual"  Stretch="Fill" Loaded="OnMediaElementLoaded" MediaOpened="MediaElement_OnMediaOpened" />

var uri = new Uri("https://f60b7719060a37f20253-4343910d3bf76239b8a83e4f56d17dc5.ssl.cf2.rackcdn.com/mov-2015-06-07-22-08-09-391574e61009867cfcb1a1641639b39e55c8a34c.mp4", UriKind.RelativeOrAbsolute);
mediaElement.Source = uri;
mediaElement.Play();//Getting exception here.

Any help please? I also tried the same using the some other http.

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
user1845163
  • 307
  • 1
  • 5
  • 17
  • At which point in your code does this exception arise ? – Dhrumil Jun 08 '15 at 06:31
  • in mediaElement.Play(); i am getting this exception – user1845163 Jun 08 '15 at 06:32
  • [What is a `NullReferenceException` and how do I fix it?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – Soner Gönül Jun 08 '15 at 06:33
  • This doesn't answer your question per se, but it does explain how to use MediaElement: http://pmichaels.net/2015/03/01/playing-media-in-windows-universal-apps/ – Paul Michaels Jun 08 '15 at 06:41
  • Related or duplicate: [How to make a wpf MediaElement play when its Source is a https uri](https://stackoverflow.com/q/51431493/774575). `MediaElement` doesn't support authentication. Before going to other solutions, try accessing the resource with `http`, the server may serve the file without encryption, if The Force is with you. – mins Oct 02 '19 at 09:53

2 Answers2

9

Commentators are trying to look smart by giving completely irrelevant information, but the MediaElement, in fact, can't play from HTTPS sources, a bug that has been acknowledged and not prioritized enough to get fixed.

You will either have to supply a non-HTTPS source url or save the content to file first and then load it (can be accomplished with a virtualized file system).

Tyrrrz
  • 2,492
  • 1
  • 19
  • 29
-1

I just found a way to do it using Universal Windows Platform (UWP). This solution successfully plays video with a MediaElement from an https source. The implementation is similar to yours except it creates a stream from the URI and sets that as the MediaElement source. Credit to https://github.com/kiewic .

https://github.com/kiewic/MediaElementWithHttpClient

MediaElement mediaPlayer = new MediaElement();
HttpClient client = new HttpClient();

Uri uri = new Uri("https://f60b7719060a37f20253-4343910d3bf76239b8a83e4f56d17dc5.ssl.cf2.rackcdn.com/mov-2015-06-07-22-08-09-391574e61009867cfcb1a1641639b39e55c8a34c.mp4");
HttpRandomAccessStream stream = await HttpRandomAccessStream.CreateAsync(client, uri);

mediaPlayer.SetSource(stream, "video/mp4");