User Tools

Site Tools


developer_center:recipe_book:webpage_api:enumerating_the_local_library

Enumerating the local library

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 FIXME 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 )
	}
});
developer_center/recipe_book/webpage_api/enumerating_the_local_library.txt · Last modified: 2013/12/28 10:49 by geekshadow