How to fix AccessDenied Error when accessing KnownFolders.MediaServerDevices?

0

I'm trying to build a simple music player for PC / Xbox One that uses DLNA as media sources, but I keep getting an AccessDenied error.

I've imported Windows.Storage, and I've enabled the Music Library capability in the App Manifest. Trying to assign / access KnownFolders.MediaServerDevices throws the AccessDenied error. From this doc, I should only need any of the Music / Picture / Video library dependencies to use MediaServerDevices, but enabling any combination of capabilities doesn't seem to work.

public MainPage()
    {
        this.InitializeComponent();

        StorageFolder MediaServerDevices;
        MediaServerDevices = KnownFolders.MediaServerDevices;
    }

This should assign the StorageFolder to MediaServerDevices, instead it throws:

System.UnauthorizedAccessException
  HResult=0x80070005
  Message=Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))

How can I fix this error?

c#
uwp
asked on Stack Overflow Jul 11, 2019 by mantecademani

1 Answer

0

MediaServiceDevice folder collects files of the specified type on the current device, not just music library or other multimedia folders. For mobile phones, it works. But for the PC, it involves access to other folders. So it’s not enough to just get the permissions of the music library.

If you want it to work on a PC, you need to get a wider range of file permissions.

Open Package.appxmanifest with code, add the namespace and new Capability:

<Package
  ... 
  xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
  IgnorableNamespaces="uap mp rescap">

  <Capabilities>
    ...
    <uap:Capability Name="musicLibrary"/>
    <rescap:Capability Name="broadFileSystemAccess"/>
  </Capabilities>

</Package>

broadFileSystemAccess is the key to access the MediaServiceDevice.

This is a restricted capability. Access is configurable in Settings > Application. Find your application and open the advanced options.

Open File System.

At this time you can access the MediaServiceDevice folder on your PC.

I hope this can help you.


User contributions licensed under CC BY-SA 3.0