1

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.

halfer
  • 19,824
  • 17
  • 99
  • 186
Muhammad Touseef
  • 4,357
  • 4
  • 31
  • 75

1 Answers1

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.

Nico Zhu
  • 32,367
  • 2
  • 15
  • 36
  • I actually get a Access-Denied exception when I try to call SavePropertiesAsync() and yes I have set capability "VideosLibrary" in my app. I tried to edit "SubTitle" property and then when tried to save it I got the exception. – Muhammad Touseef Apr 13 '18 at 10:22
  • the reason I don't want to use a database is, what if the file is deleted or moved? in that scenario my database will not know about it, and will cause unneeded complications, because the filepath changes when it moves. but if I keep the info saved on the File itself, so even if the file moves or gets deleted from FileSystem, the futureacceslist will automatically know about it, and I will not need to worry about any extra problems in that scenario. – Muhammad Touseef Apr 13 '18 at 10:26
  • Did you get file with[`FileOpenPicker`](https://learn.microsoft.com/en-us/uwp/api/windows.storage.pickers.fileopenpicker)? – Nico Zhu Apr 17 '18 at 05:47
  • No, not with fileopenpicker, I actually got KnownFolders.VideosLibrary, then with queryoptions I got the files in it and on those StorageFile objects I tried to save the properties. @Nico Zhu - MSFT – Muhammad Touseef Apr 17 '18 at 06:38
  • I have make a code sample with queryoptions, but it works in my side. Please [check](https://github.com/ZhuMingHao/VideoProperty-UWP.git). – Nico Zhu Apr 17 '18 at 07:27
  • thnks for the sample it is working fine even on my machine, so I dnt really know wht is causing problem within my app because I am using the same approach to save the properties, I am using index option in my query as well, but I even tried a simple filepicker on another page, and even that isn't working within my app. – Muhammad Touseef Apr 17 '18 at 08:52
  • I was tried to create a simpler minimal reproduction of the problem in my project so I started to delete a lot of stuff from my app. and now the problem is gone, and I don't knw wht service was causing the problem, but seems like one of the components was the reason. thanks a lot for the help though. but I think I need to do a detail analysis of my project to find out the bug :) – Muhammad Touseef Apr 17 '18 at 09:34