User Tools

Site Tools


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[";1"]

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 =;
                alert("track changed to: " + mediaItem.guid);
            case Ci.sbIMediacoreEvent.STREAM_END:
                alert("track has ended");
            case Ci.sbIMediacoreEvent.STREAM_STOP:
                alert("track was stopped");
// 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