问题
In my uwp app I am getting Video files with KnownFolders.VideoLibrary. I am able to PreFetch videoProperties of the file and also some other properties. Now I actually want to tag the video files with some string data, and save that data so I can check that later on.
For example I want to add them to Liked Videos so can I add a custom property on the storagefile which will remain saved every time I run the app. This will let me check whether a specific storagefile is liked or not.
Currently I know I can edit and save videoproperties like following.
var vp = await file.Properties.GetVideoPropertiesAsync();
vp.Title="Liked";
vp.Properties.SavePropertiesAsync();
but the problem is these properties won't be empty by default. I want a property which will be empty be default for all StorageFiles so that I can check whether they are empty or marked as Liked.
I also intend to save the token which I will get from FutureAccessList for that file. I know I can create a database table and do all of this there, but that can create other complications hence I want to keep it simple.
回答1:
There are many properties in the video file. And the official documentation does not specify that they are empty by default. However, the video property has Keywords list property, you could add Liked
keywords to the list like follow.
VideoProperties videoProperties = await file.Properties.GetVideoPropertiesAsync();
videoProperties.Keywords.Add("Liked");
await videoProperties.SavePropertiesAsync();
Although you could add the some info to keywords list, it is still very limited.
So the best practices to achieve this feature is to create a database table to record info. And you could also set a Comment
property use DocumentProperties.Comment, for more you could refer this case.
来源:https://stackoverflow.com/questions/49794568/uwp-storagefile-adding-a-custom-property