0

I am trying to run the video from https site, i am getting this exception after setting the source of the media element and invoke mediaelement.play.

Here is my code,

 <MediaElement Name="mediaElement1" LoadedBehavior="Manual" >


  mediaElement1.Source = new Uri("https://f60b7719060a37f20253-4343910d3bf76239b8a83e4f56d17dc5.ssl.cf2.rackcdn.com/mov-2015-05-25-22-01-53-a0731841b309b95209417646a2559d51077345cb.mp4");

                //mediaElement1.LoadedBehavior = MediaState.Play;
                mediaElement1.Play(); 

A first chance exception of type

'System.NullReferenceException'

occurred in PresentationCore.dll

Any help please?. Struggling for the whole day, googled but no luck.

I achieved the same using webclient, downloaded the file to temp folder and trying to play from that location. But its working in my machine, in some machine due to lack of permission its not working.

Here is my workaround

    private readonly WebClient _webClient = new WebClient();
  private string fileName ;
private string tempPath ;

 private void BtnPlay_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                tempPath = Path.GetTempPath();

                _webClient.DownloadFileCompleted += webClient_DownloadFileCompleted;

 var uri = newnew Uri("https://f60b7719060a37f20253-4343910d3bf76239b8a83e4f56d17dc5.ssl.cf2.rackcdn.com/mov-2015-05-25-22-01-53-a0731841b309b95209417646a2559d51077345cb.mp4", UriKind.RelativeOrAbsolute);
                        fileName = tempPath + uri.Segments[1];
if (!File.Exists(fileName))
                            _webClient.DownloadFileAsync(uri, fileName);
                        else
                        {
                           mediaElement.Source = new Uri(fileName, UriKind.Absolute);

                            if (mediaElement.LoadedBehavior != MediaState.Play)
                                mediaElement.Play();

                        }


            }
            catch (Exception ex)
            {


            }

        }
 void webClient_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
        {
                mediaElement.Source = new Uri(fileName, UriKind.Absolute);
                if (mediaElement.LoadedBehavior != MediaState.Play)
                    mediaElement.Play();

        }

Its not working in some machine which(temp folder) dont have write permission Thanks in advance.

user1845163
  • 277
  • 4
  • 15

0 Answers0