Songbird Wiki > Developer Center > Recipe Book > Webpage API > Enumerating the local library

Enumerating the local library

From $1

Table of contents
No headers

One of the super powerful APIs available to remote websites is the ability to enumerate the user's local library.  This can be tremendously useful for web services that want to intelligently know what the user's favourite tracks, or artists are. 

A media library, or media list, has the enumerateAllItems() API which takes an EnumerationListener object as its first (and only, if you don't pass the optional enumeration type) parameter.  An EnumerationListener is simply an object that implements onEnumerationBegin, onEnumeratedItem, and onEnumerationEnd functions.  onEnumeratedItem gets called for each item and is given the list, and the item. onEnumerationBegin & onEnumerationEnd are called once at the beginning and end of the enumeration call, and are passed the list.

Many thanks to Greg from grabb.it for this recipe.

var library = songbird.siteLibrary;
var mediaList = library.createSimpleMediaList("My Existing Playlist");

mediaList.enumerateAllItems(
{	onEnumerationBegin: function(list) {
		alert("Begin describing " + list.name);
	},
	onEnumeratedItem: function(list, item) {
		alert( item.getProperty( "http://songbirdnest.com/data/1.0#trackName" ) );
		alert( item.getProperty( "http://songbirdnest.com/data/1.0#artistName" ) );
		alert( item.getProperty( "http://songbirdnest.com/data/1.0#albumArtURL" ) );
		alert( item.getProperty( "http://songbirdnest.com/data/1.0#albumName" ) );
		alert( item.getProperty( "http://songbirdnest.com/data/1.0#trackNumber" ) );
		alert( item.getProperty( "http://songbirdnest.com/data/1.0#duration" ) );	
		alert( item.getProperty( "http://songbirdnest.com/data/1.0#originURL" ) );
							
	},
	onEnumerationEnd: function(list) {
		alert("Done describing " + list.name )
	}
});
 
Images (0)
 
Comments (0)
You must login to post a comment.