从媒体元素中的https网站播放媒体,在wpf

时间:2015-06-08 06:30:00

标签: c# wpf

我正在尝试将视频从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。

2 个答案:

答案 0 :(得分:5)

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

您必须提供非HTTPS源URL或首先将内容保存到文件然后加载(可以使用虚拟化文件系统完成)。

答案 1 :(得分:0)

我刚刚找到了一种使用通用Windows平台(UWP)的方法。此解决方案成功播放了来自https来源的MediaElement视频。该实现与您的实现类似,不同之处在于它从URI创建一个流并将其设置为MediaElement源。归功于https://github.com/kiewic

https://github.com/kiewic/MediaElementWithHttpClient

spreadsheetId = "###"  # Please set Spreadsheet ID.
sheetName = "###"  # Please set sheet name which has the columns you want to delete.

spreadsheet = client.open_by_key(spreadsheetId)
sheetId = spreadsheet.worksheet(sheetName)._properties['sheetId']
body = {
    "requests": [
        {
            "deleteDimension": {
                "range": {
                    "sheetId": sheetId,
                    "dimension": "COLUMNS",
                    "startIndex": 2,
                    "endIndex": 3
                }
            }
        }
    ]
}
res = spreadsheet.batch_update(body)
print(res)
相关问题