检查用户是否添加了新的音乐在Windows Phone 8.1 [英] Check if user added new music on Windows Phone 8.1

查看:297
本文介绍了检查用户是否添加了新的音乐在Windows Phone 8.1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找出如果用户添加了新的音乐到音乐文件夹在手机上应用以来最后一次使用。

I'm trying to find out if a user added new music to the Music folder on the phone since app was last used.

我尝试这样做检查音乐文件夹的DateModified(添加新的音乐手机时,它正确地更新计算机上):

I try to do this by checking the DateModified of the Music folder (which updates correctly 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 user added new music?

推荐答案

KnownFolders.MusicLibrary 是一个虚拟位置。因此,我认为,可能是在获得其属性的一个问题。

KnownFolders.MusicLibrary is a virtual location. Therefore I think, may be a problem in getting its properties.

另一个问题是, DateModified 可能是一个坏主意,因为当用户添加一个文件,它可能会保持不变。你不能中继就可以了。 (一些信息)。您可以检查它 - 当我试图在文件夹中移动文件,它们的 DateModified 并没有改变。

The other problem is that DateModified may be a bad idea, as it may stay the same when user adds a file. You cannot relay on it. (some information). You can check it - when I've tried to move files in folders, their DateModified hadn't changed.

因此,在这种情况下,恐怕你将不得不列出MusicLibrary文件,然后决定什么保存以供将来比较。的filesizes的总和可以是一个好主意,所以有一点点机会,两个不同的音乐文件将是大小相同。同时,如果你想,如果用户已经从一个文件夹移动文件复制到另一个(总规模不会改变)被通知要看情况。如果你想确保你越能记得元组LT的整个列表; file.FolderRelativeId,档案大小方式> (对于ecample)

So in this case, I'm afraid you will have to list your files in MusicLibrary and then decide, what to save for future comparison. The sum of filesizes can be a good idea, hence there is a little chance that two different music files would be the same size. It depends also if you want to be notified if the user had moved file from one folder to another (total size won't change). If you want to ensure more you can remember the whole list of Tuple<file.FolderRelativeId, fileSize> (for ecample).

由于FileQueries尚未公布Windows Phone的,你将不得不递归retrive文件的简单代码可以是这样的:

As FileQueries are not yet available for Windows Phone, you will have to retrive files recursively the simple code can look like this:

// 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;
}



一旦你有你的文件的列表,你可以决定如何记住在下次应用程序启动进一步的比较。

Once you have a list of your files, you can decide what to remember for further comparison upon next app launch.

这篇关于检查用户是否添加了新的音乐在Windows Phone 8.1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆