Reputation: 317
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.
Upvotes: 9
Views: 2983
Reputation: 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");
Upvotes: -1
Reputation: 2611
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).
Upvotes: 9