Check if user added new music on Windows Phone 8.1

Iโ€™m trying to find out if the user has added new music to the โ€œMusicโ€ folder on the phone since the last application was used.

I try to do this by setting the DateModified folder from Music (which correctly updates on the computer when adding new music to the phone):

async void GetModifiedDate ()
{
    BasicProperties props = await KnownFolders.MusicLibrary.GetBasicPropertiesAsync();
    Debug.WriteLine("DATEMODIFIED: " + props.DateModified.ToString());
}

Unfortunately, this returns:

DATEMODIFIED: 1/1/1601 1:00:00 AM +01:00

Am I doing something wrong or is there another quick way to check if the user has added new music?

+4
source share
3 answers

KnownFolders.MusicLibrary - , , , .

, DateModified , . . ( ). - , DateModified .

, , , MusicLibrary, , . , , . , , ( ). , Tuple<file.FolderRelativeId, fileSize> ( ecample).

FileQueries Windows Phone, , :

// first - a method to retrieve files from folder recursively 
private async Task RetriveFilesInFolder(List<StorageFile> list, StorageFolder parent)
{
    foreach (var item in await parent.GetFilesAsync()) list.Add(item);
    foreach (var item in await parent.GetFoldersAsync()) await RetriveFilesInFolder(list, item);
}

private async Task<List<StorageFile>> GetFilesInMusic()
{
    StorageFolder folder = KnownFolders.MusicLibrary;
    List<StorageFile> listOfFiles = new List<StorageFile>();
    await RetriveFilesInFolder(listOfFiles, folder);
    return listOfFiles;
}

, , , .

+2

:

ulong musicFolderSize = (ulong)ApplicationData.Current.LocalSettings.Values["musicFolderSize"];

BasicProperties props = await KnownFolders.MusicLibrary.GetBasicPropertiesAsync();
if (props.Size != musicFolderSize)
{
    //  ...
    ApplicationData.Current.LocalSettings.Values["musicFolderSize"] = props.Size;
}
0

Romansz:

, , - , , .

- KnownFolders.MusicLibrary.GetFilesAsync(CommonFileQuery.OrderByName);, . , . ,

        //cache the virtual storage folder for the loop
        StorageFolder musicLibrary = KnownFolders.MusicLibrary; 
        uint stepSize= 50;
        uint startIndex = 0;
        while (true)
        {
            IReadOnlyList<StorageFile> files = await musicLibrary.GetFilesAsync(CommonFileQuery.OrderByName,startIndex,stepSize);

            foreach (var file in files)
            {
                //compare to see if file is in your list
            }
            if (files.Count < stepSize) break; 
            startIndex += stepSize;
        }
0

Source: https://habr.com/ru/post/1541032/


All Articles