UnauthorizedAccessException using MediaPlayerElement UWP control

Andrew Allen 1 Reputation point
2019-12-03T22:51:53.963+00:00

I am trying to play a mpeg dash video stream hosted in a gninx on a UWP application (Windows 10) with MediaPlayerElement control, but I keep getting the status ManifestDownloadFailure and a System.UnauthorizedAccessException.

alt text

This is the method that I'm using:

private async void Button_Click(object sender, RoutedEventArgs e)  
    {  
        if (!string.IsNullOrEmpty(url.Text))  
        {  
            AdaptiveMediaSourceCreationResult result = await AdaptiveMediaSource.CreateFromUriAsync(new Uri(url.Text));  
  
            if (result.Status == AdaptiveMediaSourceCreationStatus.Success)  
            {  
                var ams = result.MediaSource;  
                mediaPlayerElement.Source = MediaSource.CreateFromAdaptiveMediaSource(ams);  
            }  
        }  
    }  

am I missing something?

Universal Windows Platform (UWP)
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Richard Zhang-MSFT 6,936 Reputation points
    2019-12-04T01:37:18.933+00:00

    Hello,​

    Welcome to our Microsoft Q&A platform!

    Is your url a local path? For example D: \test.mp4. If so, UWP does not have permission to access files directly through the path.

    UWP has strict management of file access permissions. You can only access your application folder and project folder through the path.

    A more recommended workflow is that you use FileOpenPicker to select a file and then create a MediaSource form the file.

    Get file

    public async static Task OpenLocalFile(params string[] types)
    {
        var picker = new FileOpenPicker();
        picker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
        foreach (var type in types)
        {
            picker.FileTypeFilter.Add(type);
        }
        var file = await picker.PickSingleFileAsync();
        return file;
    }
    

    Use

    private async void Button_Click(object sender, RoutedEventArgs e)
    {
        var file = await OpenLocalFile(".mp4");
        if(file != null)
        {
            mediaPlayerElement.Source = MediaSource.CreateFromStorageFile(file);
        }
    }
    

    Thanks