User Tools

Site Tools


developer_center:recipe_book:extensions_and_core:media_playback

Media Playback

Nightingale have a Media Core API. It's worth looking through some of the IDL files to familiarise yourself with the new API.

Getting the Media Core Manager

Pretty much anything interesting will involve first getting a reference to the Media Core Manager:

var gMM = Components.classes["@songbirdnest.com/Songbird/Mediacore/Manager;1"]
                    .getService(Components.interfaces.sbIMediacoreManager);

What's playing Now

You must first get the currently playing view, which we can get from the sequencer. Once we have the view, we can index into it from the view position (a member of the sequencer):

var mediaItem = gMM.sequencer.view.getItemByIndex(gMM.sequencer.viewPosition);

That will return you the sbIMediaItem, from which you can do the usual .getProperty(), etc.

Adding Asynchronous Callbacks (for track change, stop, etc.)

You can implement the sbIMediacoreEventListener interface in order to listen to media core events (defined in the sbIMediacoreEvent interface). Some events you can listen for:

  • Track change
  • Stop
  • Volume change
  • View (e.g. playlist) change
  • Pause

There are other events, described more thoroughly in the sbIMediacoreEvent interface (IDL). You simply pass your sbIMediacoreEventListener to gMM.addListener(), like so:

const Ci = Components.interfaces;
var myListener = {
    onMediacoreEvent: function(ev) {
        switch (ev.type) {
            case Ci.sbIMediacoreEvent.TRACK_CHANGE:
                var mediaItem = ev.data;
                alert("track changed to: " + mediaItem.guid);
                break;
            case Ci.sbIMediacoreEvent.STREAM_END:
                alert("track has ended");
                break;
            case Ci.sbIMediacoreEvent.STREAM_STOP:
                alert("track was stopped");
                break;
    }
}
gMM.addListener(myListener);
// remember to call gMM.removeListener(myListener) when appropriate!

onMediacoreEvent() is passed an event, which has a .type, indicating what event actually occured (which you can map against the events listed in the sbIMediacoreEvent interface), as well as .data which points to the payload in question. In the above example, it is the mediaItem for track change. For view change, it would be the sbIMediaListView changed to.

developer_center/recipe_book/extensions_and_core/media_playback.txt · Last modified: 2013/12/28 09:20 by geekshadow