If you've read the overview of Libraries, Playlists, and Tracks, you may be wondering how you can do free text search and/or filtering of playlists & libraries.
Songbird has the concept of sbIMediaListViews. Media list views are literally a "view of an sbIMediaList", where the view filters the media list in some way, either by applying a text-search-filter, or by filtering based on existing properties. To create a new view, you simply call .createView() on the playlist. For instance, to create a new unfiltered view of the main library:
Components.utils.import("resource://app/jsmodules/sbLibraryUtils.jsm");
Components.utils.import("resource://app/jsmodules/sbProperties.jsm");
var myView = LibraryUtils.mainLibrary.createView();
The view, at this time is unfiltered. If we wanted to load this view we could get a reference to the main browser object, and call the loadMediaList() method:
// get a pointer to the global tab browser
if (typeof(gBrowser) == "undefined")
var gBrowser = Cc["@mozilla.org/appshell/window-mediator;1"]
.getService(Ci.nsIWindowMediator)
.getMostRecentWindow("Songbird:Main").window.gBrowser;
gBrowser.loadMediaList(LibraryUtils.mainLibrary, null, null, myView,
"chrome://songbird/content/mediapages/filtersPage.xul");
If you've looked at the interface for .loadMediaList(), you may have seen that most of the parameters are optional, including the sbIMediaListView we passed as 'view'. If we only wanted to load an unfiltered view, we could have simply passed the sbIMediaList (in this case, LibraryUtils.mainLibrary) to loadMediaList() without needing any of the other parameters.sbICasecadeFilterSet instances. Every sbIMediaListView has a .cascadeFilterSet member for this purpose.myView.cascadeFilterSet.appendFilter(SBProperties.genre); var propIndex = view.cascadeFilterSet.appendFilter(SBProperties.artistName); view.cascadeFilterSet.appendFilter(SBProperties.albumName); myView.cascadeFilterSet.set(propIndex, ["Weezer"], 1);
Note that if we had any hidden items with the artistName set to "Weezer", or playlists with the name "Weezer", they would show up in this view. For this reason, we can use the sbIFilterableMediaListView's filterConstraint member and set it to an sbILibraryConstraint to further constrain the search results. The LibraryUtils JSM handily defines a LibraryUtils.standardFilterConstraint sbILibraryConstraint value for us which filters out playlists and hidden items which we can use by doing:
// By default, we never want to show lists and hidden // things in the playlist myView.filterConstraint = LibraryUtils.standardFilterConstraint;
We can then load this view, as above by doing:
gBrowser.loadMediaList(LibraryUtils.mainLibrary, null, null, myView,
"chrome://songbird/content/mediapages/filtersPage.xul");
.appendSearch() routine (analogous to the above appendFilter() call)... but an even easier option is to utilise the LibraryUtils JSM again which defines a handy createStandardMediaListView() call which takes an sbIMediaList and a string to filter on:
var myView =
LibraryUtils.createStandardMediaListView(LibraryUtils.mainLibrary, "Danger")
This would create a new sbIMediaListView view of the main library filtered on all results matching "Danger". This text search applies over the default filter properties, namely: Genre, Artist, and Album.
| Images 0 | ||
|---|---|---|
| No images to display in the gallery. |