How to Play Video File On D Drive In WinRT?

2019-07-24 23:51发布

问题:

Using XAML C# in Windows "Metro" Apps how do I go about playing a certain video file. Examples:

  • D:\video1.wmv
  • \\MEDIAPC\video2.wmv

The only way I managed to get this working so far is by using FilePicker, but I don't want to use this as I already have a list of files to play.

I have tried to use GetFileFromPathAsync but I keep getting permission / access issues

 await StorageFile.GetFileFromPathAsync(@"D:\video1.wmv");

Apologies if this has been answered I just couldn't find an answer that fits my problem.

回答1:

If your D:\ drive is a non-network resource try adding the Removable storage application capability. This can be accomplished by double-clicking on the Package.appxmanifest and navigating to the Capabilities tab. By default your application (assuming it is a Windows Store app) only has access to local files packaged with your app or files stored in local/roaming/temp folders (usually reserved for Application state).

If your data is stored on a Network resource that requires authentication you will want to enable the Enterprise Authentication capability.

You may also want to fiddle with the Home and Work Networks for the \MEDIAPC\ files if you aren't accessing resources that require network authentication.

Further Reads:

  • Accessing data and files
  • How to load data from files
  • App Capabilities Overview