c# - Get list of recently listened music -


i'm developing windows phone app needs retrieve , manipulate information songs played on device.

i know possible song playing using mediaplayer.queue.activesong.

however, need have access list of played tracks.

mediahistory , mediahistoryitem classes don't seem provide this.

is possible? how?

the current api, @igor has pointed out in answer not allow this. however, there way reasonably assume particular media file has been played recently, getting information actual file.

we can use getbasicpropertiesasync() along retrievepropertiesasync() give dateaccessed property file.

here code snippet taken this msdn page:

public async void test() {      try     {         storagefile file = await storagefile.getfilefrompathasync("filepath");         if (file != null)         {             stringbuilder outputtext = new stringbuilder();              // basic properties             basicproperties basicproperties = await file.getbasicpropertiesasync();             outputtext.appendline("file size: " + basicproperties.size + " bytes");             outputtext.appendline("date modified: " + basicproperties.datemodified);              // specify more properties retrieve             string dateaccessedproperty = "system.dateaccessed";             string fileownerproperty = "system.fileowner";             list<string> propertiesname = new list<string>();             propertiesname.add(dateaccessedproperty);             propertiesname.add(fileownerproperty);              // specified properties through storagefile.properties             idictionary<string, object> extraproperties = await file.properties.retrievepropertiesasync(propertiesname);             var propvalue = extraproperties[dateaccessedproperty];             if (propvalue != null)             {                 outputtext.appendline("date accessed: " + propvalue);             }             propvalue = extraproperties[fileownerproperty];             if (propvalue != null)             {                 outputtext.appendline("file owner: " + propvalue);             }         }     }     // handle errors catch blocks     catch (filenotfoundexception)     {         // example, handle file not found error     } } 

once have dateaccessed property in variable, can see if recent date, say, yesterday, or maybe 2 or 3 days ago. we'll know if it's been accessed within short period of time, have been played.

there caveats this, though. virus scanners change timestamp properties on files , folders, , need open files scan them assume change dateaccessed property. however, many new antivirus apps i've seen revert timestamp info original, if had never touched file.

i believe best workaround problem @ moment. unless care when your app played file. answer question simple managing own recently-played lists media files.

update


in order retrieve playcount specified song, can access song using medialibrary class:

medialibrary library = new medialibrary(); 

then access song this:

int32 playcount = library.songs[0].playcount; 

where [0] index of song you'd playcount for. easier way (depending on how you're accessing songs already, might like:

int32 playcount = library.artists[selectedartistindex].albums[selectedartistalbumindex].songs[selectedsonginalbumindex].playcount; 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -