February 2, 2009 by jabapyth
Here's a quick javascript+XPCOM recipe on how to get a list of the user's playlists in a songbird extension.
function getUserPlaylists() {
var sLM = Components.classes["@songbirdnest.com/Songbird/library/Manager;1"]
.getService(Components.interfaces.sbILibraryManager);
var aLib = sLM.mainLibrary;
var playlists = [aLib];
var pnames = [];
var listener = {
onEnumerationBegin: function() { },
onEnumerationEnd: function() { },
onEnumeratedItem: function(list, item) {
if (pnames.indexOf(item.name)==-1){ // sometimes we get smart playlists multiple times
playlists.push(item);
pnames.push(item.name);
}
return Components.interfaces.sbIMediaListEnumerationListener.CONTINUE;
}
};
aLib.enumerateItemsByProperty("http://songbirdnest.com/data/1.0#isList", "1", listener );
return playlists;
}
function playPlaylist(plist,i){ // i == index of the song you want to play
var gMM = Components.classes["@songbirdnest.com/Songbird/Mediacore/Manager;1"]
.getService(Components.interfaces.sbIMediacoreManager);
gMM.sequencer.playView(plist.createView(),i);
}
Once you get your lists of playlists, you can start one playing with playPlaylist(plist,index) or check the user-visible names with plist.name.
For more info on the songbird extension API, hit the docs or mozilla's songbird irc channel.
- jabapyth's blog
- Login or register to post comments
Recent comments
13 weeks 5 days ago
18 weeks 1 day ago
18 weeks 1 day ago
18 weeks 1 day ago
20 weeks 19 hours ago
24 weeks 2 days ago
28 weeks 5 days ago
31 weeks 6 hours ago
31 weeks 1 day ago
1 year 1 week ago