2 Components.utils.import(
"resource://gre/modules/XPCOMUtils.jsm");
3 Components.utils.import(
"resource://app/jsmodules/sbProperties.jsm");
4 Components.utils.import(
"resource://app/jsmodules/sbCoverHelper.jsm");
6 catch (error) {alert(
"Unity Integration: Unexpected error - module import error\n\n" + error)}
12 if (typeof UnityIntegration ==
'undefined') {
13 var UnityIntegration = {};
16 UnityIntegration.soundMenu = {
18 stringConverter:
null,
21 unityServiceProxy:
null,
28 var mainwindow =
window.QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsIWebNavigation)
29 .QueryInterface(Components.interfaces.nsIDocShellTreeItem).rootTreeItem
30 .QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsIDOMWindow);
32 this.xulAppInfo = Components.classes[
"@mozilla.org/xre/app-info;1"].getService(Components.interfaces.nsIXULAppInfo);
33 this.stringConverter = Components.classes[
'@mozilla.org/intl/scriptableunicodeconverter'].getService(Components.interfaces.nsIScriptableUnicodeConverter);
34 this.
gMM = Components.classes[
"@songbirdnest.com/Songbird/Mediacore/Manager;1"].getService(Components.interfaces.sbIMediacoreManager);
35 this.
wm = Components.classes[
"@mozilla.org/appshell/window-mediator;1"].getService(Components.interfaces.nsIWindowMediator);
36 this.mainwindow = this.
wm.getMostRecentWindow(
"Songbird:Main");
37 this.
prefs = Components.classes[
"@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch(
"extensions.unity-integration.");
38 this.
prefs.QueryInterface(Components.interfaces.nsIPrefBranch2);
40 UnityIntegration.soundMenu.preferencesObserver.register();
42 this.unityServiceProxy = Components.classes[
"@LookingMan.org/Songbird-Nightingale/UnityProxy;1"].getService(Components.interfaces.IUnityProxy);
44 var windowTitle = mainwindow.document.getElementById(
"mainplayer").getAttribute(
"title");
46 if (this.xulAppInfo.name ==
"Songbird")
47 this.unityServiceProxy.InitializeFor(
"songbird.desktop", windowTitle);
48 else if (this.xulAppInfo.name ==
"Nightingale")
49 this.unityServiceProxy.InitializeFor(
"nightingale.desktop", windowTitle);
51 alert(
"Unity Integration: Unexpected error - your application is not supported")
55 UnityIntegration.soundMenu.preferencesObserver.observe(
null,
"needInit",
"enableNotifications");
56 UnityIntegration.soundMenu.preferencesObserver.observe(
null,
"needInit",
"hideOnClose");
58 this.stringConverter.charset =
'utf-8';
62 var soundMenuObserver = {
65 case "sound-menu-play":
68 if (mm.status.state == sbIMediacoreStatus.STATUS_PAUSED) {
69 mm.playbackControl.play();
70 }
else if(mm.status.state == sbIMediacoreStatus.STATUS_PLAYING ||
71 mm.status.state == sbIMediacoreStatus.STATUS_BUFFERING) {
72 that.unityServiceProxy.SoundMenuSetPlayingState(
true);
77 var
event = document.createEvent(
"Events");
78 event.initEvent(
"Play",
true,
true);
79 var notHandled = that.mainwindow.dispatchEvent(
event);
83 var app = Components.classes[
"@songbirdnest.com/Songbird/ApplicationController;1"]
84 .getService(Components.interfaces.sbIApplicationController);
90 case "sound-menu-pause":
94 case "sound-menu-next":
98 case "sound-menu-previous":
105 this.
observerService = Components.classes[
"@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
106 this.
observerService.addObserver(soundMenuObserver,
"sound-menu-play",
false);
107 this.
observerService.addObserver(soundMenuObserver,
"sound-menu-pause",
false);
108 this.
observerService.addObserver(soundMenuObserver,
"sound-menu-next",
false);
109 this.
observerService.addObserver(soundMenuObserver,
"sound-menu-previous",
false);
111 this.
gMM.addListener({
112 onMediacoreEvent :
function(
event) {
113 var item =
event.data;
114 if (that.gMM.sequencer.view ==
null)
return;
115 var list = that.gMM.sequencer.view.mediaList;
117 switch (
event.type) {
118 case Components.interfaces.sbIMediacoreEvent.TRACK_CHANGE:
119 if (that.lastItem == that.gMM.sequencer.currentItem)
break;
120 else that.lastItem = that.gMM.sequencer.currentItem;
122 var
artist = that.stringConverter.ConvertFromUnicode(that.gMM.sequencer.currentItem.getProperty(SBProperties.artistName));
123 var album = that.stringConverter.ConvertFromUnicode(that.gMM.sequencer.currentItem.getProperty(SBProperties.albumName));
124 var track = that.stringConverter.ConvertFromUnicode(that.gMM.sequencer.currentItem.getProperty(SBProperties.trackName));
125 var coverFilePath =
null;
127 var resourceURL = that.gMM.sequencer.currentItem.getProperty(SBProperties.primaryImageURL);
128 if (resourceURL !=
null) {
130 var
ios = Components.classes[
"@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
131 var fileURI = ios.newURI(decodeURI(resourceURL),
null,
null).QueryInterface(Components.interfaces.nsIFileURL);
132 var fileurl = fileURI.file.path;
133 if (fileURI.file.exists())
134 coverFilePath = fileurl;
136 Cu.reportError(e +
" " + resourceURL);
140 that.unityServiceProxy.SoundMenuSetTrackInfo(track, artist, album, coverFilePath);
143 case Components.interfaces.sbIMediacoreEvent.STREAM_START:
147 case Components.interfaces.sbIMediacoreEvent.STREAM_PAUSE:
151 case Components.interfaces.sbIMediacoreEvent.STREAM_STOP:
152 case Components.interfaces.sbIMediacoreEvent.STREAM_END:
163 onUnLoad:
function () {
164 UnityIntegration.soundMenu.preferencesObserver.unregister();
167 registerOnClose:
function (force) {
168 if (this.
prefs.getBoolPref(
"hideOnClose")) {
170 this.mainwindow.onclose =
function () {
171 that.unityServiceProxy.HideWindow();
175 this.mainwindow.onclose =
"";
179 preferencesObserver: {
180 register:
function () {
181 UnityIntegration.soundMenu.prefs.addObserver(
"",
this,
false);
184 unregister:
function () {
185 UnityIntegration.soundMenu.prefs.removeObserver(
"",
this);
189 if(aTopic !=
"nsPref:changed" && aTopic !=
"needInit")
return;
191 if (
aData ==
"hideOnClose")
192 UnityIntegration.soundMenu.registerOnClose(
true);
197 window.addEventListener(
"load",
function(e) { UnityIntegration.soundMenu.onLoad(); },
false);
198 window.addEventListener(
"unload",
function(e) { UnityIntegration.soundMenu.onUnLoad(); },
false);
static nsCOMPtr< nsIObserverService > observerService
var getService(Components.interfaces.nsIWindowMediator).getMostRecentWindow('Songbird SBProperties artist
_updateTextAndScrollDataForFrame aData
sbDeviceFirmwareAutoCheckForUpdate prototype observe