I use FileActivatedEventArgs args to do the file association in my video player app. So I when user double clicks a video file it opens and plays the file in my app, also it gets all the neighbouring files, so I can add them to playlist as well. I use following code for this purpose.
var file=args.Files[0];
StorageFileQueryResult neighboringFilesQuery=args.NeighboringFilesQuery;
var startingIndexunit = await neighboringFilesQuery.FindStartIndexAsync(file);
int startingIndex = Convert.ToInt32(startingIndexunit); //this is where exception occurs
not always but sometimes when I open a file I get a System.OverFlowException because the code tries to enter a very large garbage number into int32 which causes the exception.
After further investigation I have discovered that usually when I double click a file and get neighbor files, I get all the files in NeighborFilesQuery (including the 1 file I clicked to open) so I can just find its index so I can set the start index of my playlist in my app, and play the clicked file at correct position.
But in some other cases for example when I open a .flv or some a .rm file, I get all neighbor files in the neighborfilesQuery but I don't get the file I clicked, so when the code tries to get the index of that file, that file doesn't exist in that list hence I get a garbage index.
So why is this api so inconsistent? Sometimes it includes the clicked file in query files list, and sometimes it doesn't?
Note please note that I am only talking about a single file clicked scenario here and not about multiple files opened together (because in that case the files query is supposed to be empty and that is a different scenario).