User Tools

Site Tools


developer_center:recipe_book:extensions_and_core:media_playback

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

developer_center:recipe_book:extensions_and_core:media_playback [2013/12/28 09:20] (current)
geekshadow created
Line 1: Line 1:
 +====== Media Playback ======
  
 +Nightingale have a [[http://​src.getnightingale.com/​xref/​nightingale-hacking/​components/​mediacore/​base/​public/​|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:
 +<​code>​
 +var gMM = Components.classes["​@songbirdnest.com/​Songbird/​Mediacore/​Manager;​1"​]
 +                    .getService(Components.interfaces.sbIMediacoreManager);​
 +</​code>​
 +
 +===== 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):
 +<​code>​
 +var mediaItem = gMM.sequencer.view.getItemByIndex(gMM.sequencer.viewPosition);​
 +</​code>​
 +
 +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 [[http://​src.getnightingale.com/​xref/​nightingale-hacking/​components/​mediacore/​base/​public/​sbIMediacoreEventListener.idl|sbIMediacoreEventListener interface]] in order to listen to media core events (defined in the [[http://​src.getnightingale.com/​xref/​nightingale-hacking/​components/​mediacore/​base/​public/​sbIMediacoreEvent.idl|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 [[http://​src.getnightingale.com/​xref/​nightingale-hacking/​components/​mediacore/​base/​public/​sbIMediacoreEvent.idl|sbIMediacoreEvent interface (IDL)]]. ​ You simply pass your sbIMediacoreEventListener to gMM.addListener(),​ like so:
 +<​code>​
 +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!
 +</​code>​
 +
 +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