Search code examples
c#xamluwpvideo-libraryadvanced-query-tool

uwp app AdvancedQuerySyntax for video file types


in my uwp app I am getting video files from KnownFolder.VideoLibrary and I am using QueryOptions to get them, so taking advantage of that I am trying to use AdvancedQuerySyntax so that I only get video files, but I am actually getting subtitle files like srt as well. what am I doing wrong here? is the AQS syntax I wrote wrong? I think subs files are also considered as video files according to this syntax, is there a way I can narrow it down to getting only video files excluding subtitle files? or can I get a link to docs where I can know what is the list of extension types, this syntax actually will return? So I can manage it accordingly?

CODE

            videoFileOptions = new QueryOptions()
            {
                IndexerOption = IndexerOption.OnlyUseIndexerAndOptimizeForIndexedProperties//check sort order later               
            };
            string videoFilter = "System.Kind:=System.Kind#Video";
            videoFileOptions.ApplicationSearchFilter += videoFilter;
            videoFileOptions.SetPropertyPrefetch(PropertyPrefetchOptions.VideoProperties, RequiredVideoProperties);
            videoFileOptions.SetThumbnailPrefetch(ThumbnailMode.VideosView, thumbnailRequestedSize, ThumbnailOptions.UseCurrentScale);

This is the line where I am providing the filter.

string videoFilter = "System.Kind:=System.Kind#Video";


Solution

  • Short answer: .srt and other subtitle files are classified as video files since any app supporting playback might want access to srt files.

    You can add an application search filter ext:<>.srt to remove srt files from your results.

    Long Answer: The inevitable question is why not have another type for Kind:Subtitles or something? Why include them for with Kind:Video?

    Well there is another pressure that goes on the Kind mappings beyond just "does this extension make sense as a video"? It all comes back to the SD card access on Windows Phone.

    See for Windows 8 an modern app accessing the SD card had to declare a file launch experience for any file type they wanted to see on the SD card. For example that meant that a video app would need a file launch experience for mp4, avi, ect. However, on Windows Phone this wouldn't work because there was no way for an app to override the default system app for mp4 or avi (there is another story here for another day). So we needed another way to give apps access to mp4 files on the SD card.

    The solution was that since the UI already said "Grant this app access to Videos and your SD card" then any app with both the video library capability and SD card access should have access to all files of Kind.Video on your SD card. Thus Kind.Video not only meant "Video files" but also "Files a video app would want access to".

    With this slightly changed definition, it meant that any files the built in video player needed were suddenly included in the Kinds.Video mapping. Which is where .srt files come from in the mapping.

    And as one of the people responsible for making the kind mapping decisions, I'd like to take this opportunity to apologize my mess and promise I'm not nearly as brain dead as you'd think looking at this design. Probably