在 UWP 中访问文件 [英] Access to file in UWP

查看:24
本文介绍了在 UWP 中访问文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为 Windows Universal 10 开发视频播放器(目标版本:10.0.10240.0)

I'm developing an video player for Windows Universal 10 (target version: 10.0.10240.0)

我可以将文件从 PC 启动到我的应用程序并随心所欲地播放视频.当我启动视频时,问题开始于我想要,文件夹中与视频同名的字幕在应用程序中获取,例如,我在我的电脑的某个地方有这些文件:

I'm able to launch files from PC to my app and play video as well as I want. The problem starts with I want when I launch a video, subtitle with the same name of video in the folder get it in application, for example I have these files in somewhere in my pc:

The.Originals.S03E14.480p.mkv

The.Originals.S03E14.480p.mkv

The.Originals.S03E14.480p.srt

The.Originals.S03E14.480p.srt

我希望当我启动这个 mkv 文件时,也可以访问 srt 文件.我使用的代码:

I want when i Launched this mkv file, can access to srt file too. the code I used:

StorageFile file = args.Files[0] as StorageFile; // Launched file
string filePath = file.Path;
filePath = filePath.Replace(Path.GetExtension(filePath), ".srt");
StorageFile file2 = await StorageFile.GetFileFromPathAsync(filePath);

但是为了获得字幕,它给了我访问被拒绝的异常.

but for getting subtitle, it gives me ACCESS DENIED exception.

是否可以在不启动的情况下获得字幕?

Is this possible to get subtitle without launching them?

谢谢

推荐答案

简短的回答是否定的.最好的解决方案是允许用户通过文件选择器手动指定 SRT 文件.您只能访问用户通过选择器选择的文件.您还可以访问视频库文件夹(应该在清单权限中指定),但我假设您需要从任何位置播放文件.有关更多信息,请查看以下链接:https://stackoverflow.com/a/33083243/1099716例如,即使是微软也无法实现普通的图像查看器.本机 Windows 10 图像查看器应用无法在图片之间导航,因为它无法访问同一文件夹中的文件.

The short answer is no. The best solution would be to allow user specify SRT file manually via file picker. You can access only files which user has picked via picker. You can also access Video library folder (it should be specified in manifest permissions), but I assume you need to play file from any location. For more info take a look at the following link: https://stackoverflow.com/a/33083243/1099716 For example, even microsoft was unable to implement normal image viewer. Native windows 10 image viewer app can't navigate between pictures, since it can't access files in the same folder.

这篇关于在 UWP 中访问文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆