如何访问Microsoft Graph DriveItem(视频)内容流以与MediaPlayerElement一起使用(使用Graph .NET SDK)

时间:2019-04-14 15:55:09

标签: c# uwp microsoft-graph onedrive

使用Microsoft Graph .NET SDK,我试图访问DriveItem的内容流,该内容是视频,以便可以在UWP MediaPlayerElement中播放。但是,部署后,MediaPlayerElement将显示:

  

“错误:不支持的视频类型或无效的文件路径”。

我可以使用Windows Community Toolkit访问Microsoft Graph,并实现了Files.ReadWrite.All权限。我还根据需要得到了DriveItem id

private async void LoadVideo(DriveItem driveItem) {
    var graphClient = MicrosoftGraphService.Instance.GraphProvider;

    using(Stream responseStream = await graphClient
        .Me
        .Drive
        .Items[driveItem.Id]
        .Content
        .Request().GetAsync()) {
        var memoryStream = responseStream as MemoryStream;
        if (responseStream != null) {
            // Breakpoint on this line is reached after 
            // a substantial delay on the using statement 
            // line. At this line, the memoryStream has a value of 89400353.
            MyMPE.Source = MediaSource
                .CreateFromStream(memoryStream
                    .AsRandomAccessStream(), "video/mp4");
        } else {
            ...
        }
    }
}

if语句始终运行。当我在MyMPE.Source…开头的行上放置一个断点时,using语句上有一个相当大的延迟才到达断点。然后,MediaPlayerElement在播放器底部显示错误“错误:不支持的视频类型或无效的文件路径”。

0 个答案:

没有答案