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