【问题标题】:Playing media from https site in media element throwing null reference exception in wpf在媒体元素中播放来自 https 站点的媒体,在 wpf 中引发空引用异常
【发布时间】:2015-06-08 06:30:00
【问题描述】:

我正在尝试将来自 https 站点的视频播放到我的媒体元素中,引发以下异常。

“System.NullReferenceException”类型的异常发生在 PresentationCore.dll 但未在用户代码中处理

附加信息:对象引用未设置为 对象。

这是我在 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.

有什么帮助吗?我也尝试过使用其他一些http。

【问题讨论】:

标签: c# wpf


【解决方案1】:

评论者试图通过提供完全不相关的信息来看起来很聪明,但实际上,MediaElement 无法从 HTTPS 源播放,bug that has been acknowledged and not prioritized enough to get fixed

您要么必须提供非 HTTPS 源 URL,要么先将内容保存到文件然后加载(可以通过虚拟文件系统完成)。

【讨论】:

    【解决方案2】:

    我刚刚找到了一种使用通用 Windows 平台 (UWP) 的方法。此解决方案使用来自 https 源的 MediaElement 成功播放视频。该实现与您的类似,只是它从 URI 创建一个流并将其设置为 MediaElement 源。归功于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");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多