2 if (typeof ShoutcastRadio ==
'undefined') {
3 var ShoutcastRadio = {};
6 if (typeof
Cc ==
'undefined')
7 var
Cc = Components.classes;
8 if (typeof
Ci ==
'undefined')
9 var
Ci = Components.interfaces;
10 if (typeof
Cu ==
'undefined')
11 var
Cu = Components.utils;
13 Cu.import(
"resource://shoutcast-radio/Utils.jsm", ShoutcastRadio);
14 Cu.import(
"resource://app/jsmodules/SBDataRemoteUtils.jsm");
16 if (typeof(
gMM) ==
"undefined")
17 var
gMM = Cc[
"@songbirdnest.com/Songbird/Mediacore/Manager;1"]
18 .getService(Ci.sbIMediacoreManager);
20 #ifdef METRICS_ENABLED
21 if (typeof(gMetrics) ==
"undefined")
22 var gMetrics = Cc[
"@songbirdnest.com/Songbird/Metrics;1"]
23 .createInstance(Ci.sbIMetrics);
26 if (typeof(FAVICON_PATH) ==
"undefined")
27 const FAVICON_PATH =
"chrome://shoutcast-radio/skin/shoutcast_favicon.png";
35 this._remoteShuffleDisabled =
37 this._remoteRepeatDisabled =
39 this._remotePreviousDisabled =
41 this._remoteNextDisabled =
45 if(this._remoteShuffleDisabled) {
46 this._remoteShuffleDisabled.unbind();
47 this._remoteShuffleDisabled =
null;
49 if(this._remoteRepeatDisabled) {
50 this._remoteRepeatDisabled.unbind();
51 this._remoteRepeatDisabled =
null;
53 if(this._remotePreviousDisabled) {
54 this._remotePreviousDisabled.unbind();
55 this._remotePreviousDisabled =
null;
57 if(this._remoteNextDisabled) {
58 this._remoteNextDisabled.unbind();
59 this._remoteNextDisabled =
null;
62 onMediacoreEvent :
function(ev) {
64 if (gMM.sequencer.view ==
null)
68 case Ci.sbIMediacoreEvent.STREAM_START:
70 var currentItem = gMM.sequencer.view.getItemByIndex(
71 gMM.sequencer.viewPosition);
74 if (mmListener.time) {
75 var
now = Date.now()/1000;
76 var diff = now - mmListener.time;
77 #ifdef METRICS_ENABLED
78 gMetrics.metricsAdd(
"shoutcast",
"stream",
"time", diff);
84 if (!currentItem.getProperty(
SC_id)) {
85 mmListener.time =
null;
86 mmListener.setPlayerState(
false);
87 mmListener.playingTrack =
null;
92 mmListener.playingTrack = item;
93 mmListener.setDataRemotes();
94 mmListener.setPlayerState(
true);
98 mmListener.time = Date.now()/1000;
100 case Ci.sbIMediacoreEvent.BEFORE_TRACK_CHANGE:
101 mmListener.setPlayerState(
false);
103 case Ci.sbIMediacoreEvent.STREAM_END:
104 case Ci.sbIMediacoreEvent.STREAM_STOP:
105 mmListener.setPlayerState(
false);
106 mmListener.playingTrack =
null;
109 if (!mmListener.time) {
110 mmListener.time =
null;
113 var
now = Date.now()/1000;
114 var diff = now - mmListener.time;
115 #ifdef METRICS_ENABLED
116 gMetrics.metricsAdd(
"shoutcast",
"stream",
"time", diff);
118 mmListener.time =
null;
120 case Ci.sbIMediacoreEvent.METADATA_CHANGE:
121 var currentItem = gMM.sequencer.currentItem;
122 if (currentItem.getProperty(
SC_id) == -1 &&
123 currentItem.getProperty(SBProperties.bitRate) ==
null)
125 dump(
"Manually added stream!\n");
127 for (var
i=0;
i<props.length;
i++) {
128 var prop = props.getPropertyAt(
i);
129 dump(prop.id +
" == " + prop.value +
"\n");
130 if (prop.id == SBProperties.bitRate) {
131 dump(
"bitrate!!!!!!!\n");
133 Cc[
'@songbirdnest.com/Songbird/library/Manager;1'].getService(Ci.sbILibraryManager);
135 var l = libraryManager.getLibrary(libGuid.value);
136 var a = l.getItemsByProperty(
137 SBProperties.customType,
138 "radio_favouritesList");
139 var faves = a.queryElementAt(0, Ci.sbIMediaList);
141 var item = faves.getItemByGuid(
142 currentItem.getProperty(
143 SBProperties.outerGUID));
144 dump(
"item: " + item.guid +
"\n");
145 dump(
"outer; " + currentItem.getProperty(SBProperties.outerGUID));
146 item.setProperty(SBProperties.bitRate,
157 setPlayerState:
function(scStream) {
158 var stationIcon = document.getElementById(
"shoutcast-station-icon");
161 stationIcon.style.visibility =
"visible";
163 stationIcon.style.visibility =
"collapse";
167 setDataRemotes:
function() {
168 this._remoteShuffleDisabled.boolValue =
true;
170 this._remoteRepeatDisabled.boolValue =
true;
172 this._remotePreviousDisabled.boolValue =
true;
174 this._remoteNextDisabled.boolValue =
true;
181 ShoutcastRadio.Controller = {
182 SB_NS:
"http://songbirdnest.com/data/1.0#",
183 SP_NS:
"http://songbirdnest.com/rdf/servicepane#",
187 this._initialized =
true;
188 this._strings = document.getElementById(
"shoutcast-radio-strings");
191 var SPS = Cc[
'@songbirdnest.com/servicepane/service;1'].
195 if (SPS.getNode(
"SB:RadioStations:SHOUTcast"))
199 var radioFolder = SPS.getNode(
"SB:RadioStations");
201 radioFolder = SPS.createNode();
202 radioFolder.id =
"SB:RadioStations";
203 radioFolder.className =
"folder radio";
204 radioFolder.name = this._strings.getString(
"radioFolderLabel");
205 radioFolder.setAttributeNS(this.
SB_NS,
"radioFolder", 1);
206 radioFolder.setAttributeNS(this.SP_NS,
"Weight", 2);
207 SPS.root.appendChild(radioFolder);
209 radioFolder.editable =
false;
210 radioFolder.hidden =
false;
213 var
node = SPS.createNode();
214 node.url =
"chrome://shoutcast-radio/content/directory.xul";
215 node.id =
"SB:RadioStations:SHOUTcast";
216 node.name =
"SHOUTcast";
217 node.image = FAVICON_PATH;
218 radioFolder.appendChild(node);
219 node.editable =
false;
223 ShoutcastRadio.Utils.ensureFavouritesNode();
227 gMM.addListener(mmListener);
232 .getService(Ci.sbIFaceplateManager);
233 var pane = faceplateManager.getPane(
"songbird-dashboard");
234 var sbWindow = Cc[
"@mozilla.org/appshell/window-mediator;1"]
235 .getService(Ci.nsIWindowMediator)
236 .getMostRecentWindow(
"Songbird:Main").window;
240 var pMgr = Cc[
"@songbirdnest.com/Songbird/Properties/PropertyManager;1"]
241 .getService(Ci.sbIPropertyManager);
243 var pI = Cc[
"@songbirdnest.com/Songbird/Properties/Info/Text;1"]
244 .createInstance(Ci.sbITextPropertyInfo);
246 pI.displayName = this._strings.getString(
"streamName");
247 pI.userEditable =
false;
248 pI.userViewable =
false;
249 pMgr.addPropertyInfo(pI);
252 var pI = Cc[
"@songbirdnest.com/Songbird/Properties/Info/Number;1"]
253 .createInstance(Ci.sbINumberPropertyInfo);
255 pI.displayName = this._strings.getString(
"bitRate");
256 pI.userEditable =
false;
257 pI.userViewable =
false;
258 pMgr.addPropertyInfo(pI);
261 var pI = Cc[
"@songbirdnest.com/Songbird/Properties/Info/Text;1"]
262 .createInstance(Ci.sbITextPropertyInfo);
264 pI.displayName = this._strings.getString(
"comment");
265 pI.userEditable =
false;
266 pI.userViewable =
false;
267 pMgr.addPropertyInfo(pI);
270 var pI = Cc[
"@songbirdnest.com/Songbird/Properties/Info/Number;1"]
271 .createInstance(Ci.sbINumberPropertyInfo);
273 pI.displayName = this._strings.getString(
"listenerCount");
274 pI.userEditable =
false;
275 pI.userViewable =
false;
276 pMgr.addPropertyInfo(pI);
280 "@songbirdnest.com/Songbird/Properties/Builder/Image;1"]
281 .createInstance(Ci.sbIImagePropertyBuilder);
283 builder.displayName = this._strings.getString(
"bookmark");
284 builder.userEditable =
false;
285 builder.userViewable =
false;
286 var pI = builder.get();
287 pMgr.addPropertyInfo(pI);
289 if (!pMgr.hasProperty(
SC_id)) {
290 var pI = Cc[
"@songbirdnest.com/Songbird/Properties/Info/Number;1"]
291 .createInstance(Ci.sbINumberPropertyInfo);
293 pI.displayName =
"StreamID";
294 pI.userEditable =
false;
295 pI.userViewable =
false;
296 pMgr.addPropertyInfo(pI);
300 shoutcastUninstallObserver.register();
312 ShoutcastRadio.Controller._prefBranch =
313 Cc[
"@mozilla.org/preferences-service;1"]
314 .getService(Ci.nsIPrefService).getBranch(
"songbird.metadata.")
315 .QueryInterface(Ci.nsIPrefBranch2);
316 ShoutcastRadio.Controller._prefBranch.addObserver(
"title",
317 ShoutcastRadio.Controller.metadataObserver,
false);
320 Application.prefs.setValue(
"extensions.shoutcast-radio.filter",
"");
323 onUnLoad:
function() {
324 this._initialized =
false;
325 gMM.removeListener(mmListener);
329 var sbWindow = Cc[
"@mozilla.org/appshell/window-mediator;1"]
330 .getService(Ci.nsIWindowMediator)
331 .getMostRecentWindow(
"Songbird:Main").window;
338 ShoutcastRadio.Controller.metadataObserver = {
342 item = gMM.sequencer.currentItem;
347 if (subject instanceof Ci.nsIPrefBranch) {
350 "extensions.shoutcast-radio.title-parsing",
true))
353 var title = subject.getCharPref(
data);
357 var m = title.match(/^(.+) - ([^-]+)$/);
359 ShoutcastRadio.Controller.ts = Date.now();
360 item.setProperty(SBProperties.artistName, m[1]);
361 item.setProperty(SBProperties.trackName, m[2]);
363 var ev = gMM.createEvent(Ci.sbIMediacoreEvent.TRACK_CHANGE,
364 gMM.primaryCore, item);
365 gMM.QueryInterface(Ci.sbIMediacoreEventTarget)
376 if (typeof(Ci.sbIMediacoreManager) !=
"undefined") {
377 list = gMM.sequencer.view.mediaList;
379 gPPS = Cc[
'@songbirdnest.com/Songbird/PlaylistPlayback;1']
380 .getService(Ci.sbIPlaylistPlayback);
381 list = gPPS.playingView.mediaList;
385 if (list.getProperty(SBProperties.customType) ==
"radio_tempStreamList") {
387 if (typeof(Ci.sbIMediacoreManager) !=
"undefined") {
388 streamName = gMM.sequencer.view.getItemByIndex(
391 streamName = list.getItemByGuid(gPPS.currentGUID)
396 var
tabs = gBrowser.mTabs;
398 var loadURL =
"http://shoutcast.com/directory/?s=" + escape(streamName);
399 for (var
i=0;
i<tabs.length;
i++) {
400 var curBrowser = gBrowser.getBrowserAtIndex(
i);
401 var loadingURI = curBrowser.userTypedValue;
403 if (loadingURI !=
null)
404 compValue = loadingURI;
406 compValue = curBrowser.currentURI.spec;
407 if (compValue == loadURL) {
414 gBrowser.selectedTab = tabs[found];
417 gBrowser.loadOneTab(loadURL);
425 var shoutcastUninstallObserver = {
431 if (topic ==
"em-action-requested") {
433 subject.QueryInterface(Ci.nsIUpdateItem);
435 if (subject.id ==
"shoutcast-radio@getnightingale.com") {
436 if (
data ==
"item-uninstalled") {
437 this._uninstall =
true;
438 }
else if (
data ==
"item-cancel-action") {
439 this._uninstall =
false;
442 }
else if (topic ==
"quit-application-granted") {
445 if (this._uninstall) {
448 var
prefs = Cc[
"@mozilla.org/preferences-service;1"]
449 .getService(Components.interfaces.nsIPrefService);
450 var scPrefs = prefs.getBranch(
"extensions.shoutcast-radio.");
454 if (scPrefs.prefHasUserValue(
"plsinit"))
455 scPrefs.clearUserPref(
"plsinit");
456 if (scPrefs.prefHasUserValue(
"filter"))
457 scPrefs.clearUserPref(
"filter");
458 if (scPrefs.prefHasUserValue(
"custom-genres"))
459 scPrefs.clearUserPref(
"custom-genres");
460 if (scPrefs.prefHasUserValue(
"library.guid")) {
461 radioLibGuid = scPrefs.getCharPref(
"library.guid");
462 scPrefs.clearUserPref(
"library.guid");
464 if (scPrefs.prefHasUserValue(
"templib.guid")) {
465 tempLibGuid = scPrefs.getCharPref(
"templib.guid");
466 scPrefs.clearUserPref(
"templib.guid");
468 scPrefs.deleteBranch(
"");
472 var libMgr = Cc[
'@songbirdnest.com/Songbird/library/Manager;1']
473 .getService(Ci.sbILibraryManager);
474 var radioLib = libMgr.getLibrary(radioLibGuid);
475 var tempLib = libMgr.getLibrary(tempLibGuid);
478 libMgr.unregisterLibrary(radioLib);
479 libMgr.unregisterLibrary(tempLib);
480 dump(
"unregistered Shoutcast libraries\n");
489 register :
function() {
491 .getService(Ci.nsIObserverService);
492 observerService.addObserver(
this,
"em-action-requested",
false);
493 observerService.addObserver(
this,
"quit-application-granted",
false);
496 unregister :
function() {
497 var observerService = Cc[
"@mozilla.org/observer-service;1"]
498 .getService(Ci.nsIObserverService);
499 observerService.removeObserver(
this,
"em-action-requested");
500 observerService.removeObserver(
this,
"quit-application-granted");
504 window.addEventListener(
"load",
505 function(e) { ShoutcastRadio.Controller.onLoad(e); },
false);
506 window.addEventListener(
"unload",
507 function(e) { ShoutcastRadio.Controller.onUnLoad(e); },
false);
static nsCOMPtr< nsIObserverService > observerService
var faceplateManager
FaceplateManager test file.
getService(Ci.sbIFaceplateManager)
const shoutcastTempLibGuid
_getSelectedPageStyle s i
sbDeviceFirmwareAutoCheckForUpdate prototype observe