If things look a little dusty around here, it's because I'm away on a mission for two years. I'll be back in August 2012, but in the mean time feel free to fork my projects on github.
Songbird Recipe: Playlists
Feb 02, 2009
by Jared

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.

blog comments powered by Disqus