Wrong code is wrong.

Getting a library-wide total playCount for a given artist

Posted: May 29th, 2009 | Author: | Filed under: Milestone ii | Tags: , , | No Comments »
1
2
3
4
5
6
7
8
9
10
var destroyerPlays = LibraryUtils.mainLibrary.getItemsByProperty(SBProperties.artistName,"Destroyer");
var destroyerPlaysNames = destroyerPlays.enumerate();
destroyerPlayCounts = 0;
while (destroyerPlaysNames.hasMoreElements()) {
  var thesePlayCounts = destroyerPlaysNames.getNext();
  if (thesePlayCounts.getProperty(SBProperties.playCount)>0) {
    destroyerPlayCounts = destroyerPlayCounts + parseInt(thesePlayCounts.getProperty(SBProperties.playCount));
  };
}
alert ( destroyerPlayCounts );

I know my variable names suck right now. I know. This took two and a half hours of mucking around aimlessly before it worked. That it works is what’s important.

My question is, doesn’t line 1 define destroyerPlays as a sbIMediaList object? Then why aren’t some of the sbIMediaList methods available to it? And what is that enumerate method? I couldn’t even find any documentation on it. Apparently it takes no arguments and returns an actual sbIMediaList.

And why is SBProperties.playCount a string rather than an integer?