To be informed of updates to a playlist or library, you can use an sbIMediaListListener. These are added using sbIMediaList.addListener()
. For example, if you want your listener to be triggered when items are added or removed:
Components.utils.import("resource://app/jsmodules/sbLibraryUtils.jsm"); var myListener = { onItemAdded: function(list, item, i) { alert("Item with guid: " + item.guid + " added to: " + list.name); }, onAfterItemRemoved: function(list, item, i) { alert("Item with guid: " + item.guid + " removed from: " + list.name); } } LibraryUtils.mainLibrary.addListener(myListener, false, LibraryUtils.mainLibrary.LISTENER_FLAGS_ITEMADDED | LibraryUtils.mainLibrary.LISTENER_FLAGS_AFTERITEMREMOVED, null);
The above listener (myListener) will be triggered anytime any item is added or removed. For more granular events where properties may be involved, you can pass a property filter as the 4th argument to addListener(). For instance, if you want to be triggered whenever a user changes the artist name in the main library:
Components.utils.import("resource://app/jsmodules/sbLibraryUtils.jsm"); Components.utils.import("resource://app/jsmodules/sbProperties.jsm"); var Cc = Components.classes; var Ci = Components.interfaces; var myListener = { onItemUpdated: function(list, item, i) { alert("Item with guid: " + item.guid + " was updated!"); }, } var propertyArray = Cc["@songbirdnest.com/Songbird/Properties/MutablePropertyArray;1"] .createInstance(Ci.sbIPropertyArray); // The actual property value is ignored for mediaListListeners propertyArray.appendProperty(SBProperties.artistName, "ignored"); LibraryUtils.mainLibrary.addListener(myListener, false, LibraryUtils.mainLibrary.LISTENER_FLAGS_ITEMUPDATED, propertyArray);
The full list of listener topics/flags (e.g. the LISTENER_FLAGS_*) can be found in the sbIMediaList API reference while the interface for what your media list listener should look like can be found in the sbIMediaListListener API reference
.