29 if (
"undefined" == typeof(
Ci)) {
30 this.
Ci = Components.interfaces;
32 if (
"undefined" == typeof(
Cc)) {
33 this.
Cc = Components.classes;
35 if (
"undefined" == typeof(
Cr)) {
36 this.
Cr = Components.results;
39 Components.utils.import(
"resource://app/jsmodules/sbLibraryUtils.jsm");
44 var locationVal = aIsOnTop ?
"top" :
"bottom";
45 var contentPlayerWrapper = document.getElementById(
"content_player_wrapper");
46 if (contentPlayerWrapper) {
48 #ifdef METRICS_ENABLED
52 Components.classes[
"@songbirdnest.com/Songbird/Metrics;1"]
53 .createInstance(Components.interfaces.sbIMetrics)
54 .metricsInc(
"mainplayer.playercontrols",
"location", locationVal);
58 contentPlayerWrapper.setAttribute(
"playercontrols", locationVal);
62 var broadcasterTop = document.getElementById(
"playercontrols_top");
63 var broadcasterBottom = document.getElementById(
"playercontrols_bottom");
65 broadcasterTop.setAttribute(
"checked",
"true");
66 broadcasterBottom.removeAttribute(
"checked");
69 broadcasterBottom.setAttribute(
"checked",
"true");
70 broadcasterTop.removeAttribute(
"checked");
78 doCommand:
function(aCommand)
80 function dispatchEvent(aType, aCanBubble, aCanCancel, aTarget) {
81 var newEvent = document.createEvent(
"Events");
82 newEvent.initEvent(aType, aCanBubble, aCanCancel);
83 return (aTarget ||
window).dispatchEvent(newEvent);
87 Cc[
"@songbirdnest.com/Songbird/Mediacore/Manager;1"]
88 .getService(Components.interfaces.sbIMediacoreManager);
89 var status = mm.status;
90 if (aCommand ==
"cmd_find") {
95 var searchBar =
window.gSearchHandler.getSearchBar();
105 }
else if (aCommand ==
"cmd_findAgain") {
107 }
else if (aCommand ==
"cmd_print") {
109 }
else if (aCommand ==
"cmd_metadata") {
111 }
else if (aCommand ==
"cmd_editmetadata") {
112 SBTrackEditorOpen(
"edit");
113 }
else if (aCommand ==
"cmd_viewmetadata") {
114 SBTrackEditorOpen(
"summary");
115 }
else if (aCommand ==
"cmd_getartwork") {
117 }
else if (aCommand ==
"cmd_exportmedia") {
118 var exportService =
Cc[
"@songbirdnest.com/media-export-service;1"]
119 .getService(
Ci.sbIMediaExportService);
120 exportService.exportSongbirdData();
121 }
else if (aCommand ==
"cmd_reveal") {
123 }
else if (aCommand ==
"cmd_find_current_track") {
124 if (!mm.sequencer.view) {
133 document.documentElement.focus();
143 gTabBrowser.showIndexInView(mm.sequencer.view, mm.sequencer.viewPosition);
144 }
else if (aCommand ==
"cmd_control_playpause") {
146 if (status.state == status.STATUS_PLAYING ||
147 status.state == status.STATUS_BUFFERING) {
148 mm.playbackControl.pause();
150 else if(status.state == status.STATUS_PAUSED) {
151 mm.playbackControl.play();
157 var
event = document.createEvent(
"Events");
158 event.initEvent(
"Play",
true,
true);
161 }
else if (aCommand ==
"cmd_control_next") {
163 }
else if (aCommand ==
"cmd_control_previous") {
164 mm.sequencer.previous();
165 }
else if (aCommand ==
"cmd_volume_down") {
166 mm.volumeControl.volume = Math.max(0, mm.volumeControl.volume - 0.05);
167 }
else if (aCommand ==
"cmd_volume_up") {
168 mm.volumeControl.volume = Math.min(1, mm.volumeControl.volume + 0.05);
169 }
else if (aCommand ==
"cmd_volume_mute") {
170 mm.volumeControl.mute = !mm.volumeControl.mute;
171 }
else if (aCommand ==
"cmd_delete") {
172 SBDeleteMediaList(this._getTargetPlaylist());
173 }
else if (aCommand ==
"cmd_mediapage_next") {
178 supportsCommand:
function(aCommand)
182 case "cmd_findAgain":
186 case "cmd_editmetadata":
187 case "cmd_viewmetadata":
189 case "cmd_find_current_track":
190 case "cmd_exportmedia":
192 case "cmd_control_playpause":
193 case "cmd_control_next":
194 case "cmd_control_previous":
196 case "cmd_getartwork":
198 return (this._getTargetPlaylist() !=
null);
199 case "cmd_volume_down":
200 case "cmd_volume_up":
201 case "cmd_volume_mute":
203 case "cmd_mediapage_next":
209 isCommandEnabled:
function(aCommand)
212 if (typeof SBGetBrowser ==
'function') {
213 browser = SBGetBrowser();
216 if (browser && browser.currentMediaPage) {
217 view = browser.currentMediaPage.mediaListView;
221 Cc[
"@songbirdnest.com/Songbird/Mediacore/Manager;1"]
222 .getService(Components.interfaces.sbIMediacoreManager);
223 var status = mm.status;
225 var playing = ( status.state == status.STATUS_BUFFERING ||
226 status.state == status.STATUS_PLAYING ||
227 status.state == status.STATUS_PAUSED );
230 return (!browser.shouldDisableFindForSelectedTab());
231 case "cmd_findAgain":
232 return (!browser.shouldDisableFindAgainForSelectedTab());
235 return !(browser.contentDocument instanceof XULDocument);
237 case "cmd_editmetadata":
238 case "cmd_viewmetadata": {
240 return view.selection.count > 0;
244 case "cmd_getartwork":
245 return (view !=
null);
246 case "cmd_exportmedia":
247 var exportService =
Cc[
"@songbirdnest.com/media-export-service;1"]
248 .getService(
Ci.sbIMediaExportService);
249 return exportService.hasPendingChanges;
251 if (view && view.selection.count == 1) {
252 var selection = view.selection.selectedIndexedMediaItems;
253 var item = selection.getNext()
254 .QueryInterface(
Ci.sbIIndexedMediaItem).mediaItem;
255 var
uri = item.contentSrc;
256 return (uri && uri.scheme ==
"file");
260 case "cmd_find_current_track":
261 return mm.sequencer.view ?
true :
false;
262 case "cmd_control_playpause":
264 case "cmd_control_next":
265 case "cmd_control_previous":
266 var status = mm.status;
267 var playing = ( status.state == status.STATUS_PLAYING ||
268 status.state == status.STATUS_BUFFERING ||
269 status.state == status.STATUS_PAUSED );
270 return playing && document.commandDispatcher.focusedWindow ==
window;
273 if(node && node.editable ==
false) {
277 case "cmd_volume_down":
278 return mm.volumeControl.volume > 0;
279 case "cmd_volume_up":
280 return mm.volumeControl.volume < 1;
281 case "cmd_volume_mute":
283 case "cmd_mediapage_next":
284 return (view !=
null);
289 _getTargetPlaylist:
function()
295 Components.classes[
'@songbirdnest.com/servicepane/library;1']
296 .getService(Components.interfaces.sbILibraryServicePaneService);
297 list = libraryServicePane.getLibraryResourceForNode(knode);
301 if (typeof SBGetBrowser ==
'function')
302 browser = SBGetBrowser();
304 if (browser.currentMediaPage) {
305 var view = browser.currentMediaPage.mediaListView;
307 list = view.mediaList;
314 list.getProperty(SBProperties.outerGUID);
316 return list.library.getMediaItem(outerListGuid);
342 window.removeEventListener(
"load", this._onLoadCallback,
false);
343 this._onLoadCallback =
null;
345 this._onUnloadCallback =
function(e) { gSongbirdPlayerWindow.onUnload(e); };
346 window.addEventListener(
"unload",
347 this._onUnloadCallback,
false);
349 this._onPlayCallback =
function(e) { gSongbirdPlayerWindow.onPlay(e); };
350 window.addEventListener(
"Play", this._onPlayCallback,
false);
352 window.addEventListener(
"keypress", this.onMainWindowKeyPress,
false);
358 top.controllers.insertControllerAt(0, gSongbirdWindowController);
361 var playerControlsLocation =
366 var timingService =
Cc[
"@songbirdnest.com/Songbird/TimingService;1"]
367 .getService(
Ci.sbITimingService);
371 timingService.startPerfTimer(
"CSPerfLibrary");
372 timingService.stopPerfTimer(
"CSPerfLibrary");
373 timingService.stopPerfTimer(
"CSPerfEndEULA");
387 window.removeEventListener(
"unload", this._onUnloadCallback,
false);
388 this._onUnloadCallback =
null;
390 window.removeEventListener(
"Play", this._onPlayCallback,
false);
391 this._onPlayCallback =
null;
393 window.removeEventListener(
"keypress", this.onMainWindowKeyPress,
false);
402 onPlay:
function onPlay(
event )
407 var view = this._getMediaListViewForEvent(
event);
410 if (!(view && view.length > 0)) {
411 view = gBrowser.currentMediaListView;
415 if (!(view && view.length > 0) && gBrowser.mediaTab) {
416 view = gBrowser.mediaTab.mediaListView;
420 if (view && view.length > 0) {
422 Cc[
"@songbirdnest.com/Songbird/Mediacore/Manager;1"]
423 .getService(
Ci.sbIMediacoreManager);
425 mm.sequencer.playView(view,
426 Math.max(view.selection.currentIndex,
427 Ci.sbIMediacoreSequencer.AUTO_PICK_INDEX));
431 event.preventDefault();
434 Components.utils.reportError(e);
439 onMainWindowKeyPress:
function onMainWindowKeyPress(
event )
442 if (document.commandDispatcher.focusedWindow !=
window ||
443 document.commandDispatcher.focusedElement)
450 if (
event.charCode != KeyboardEvent.DOM_VK_SPACE ||
456 doMenu(
"menuitem_control_play");
457 event.preventDefault();
458 event.stopPropagation();
462 nextMediaPage:
function gSongbirdPlayerWindow_nextMediaPage() {
464 if (typeof SBGetBrowser !=
'function')
469 var mediaListView = browser.currentMediaListView;
470 if (!mediaListView) {
475 var mediaPageMgr =
Cc[
"@songbirdnest.com/Songbird/MediaPageManager;1"]
476 .getService(
Ci.sbIMediaPageManager);
477 var
pages = mediaPageMgr.getAvailablePages(mediaListView.mediaList);
478 var
LSP =
Cc[
"@songbirdnest.com/servicepane/library;1"]
479 .getService(
Ci.sbILibraryServicePaneService);
480 var type = LSP.getNodeContentTypeFromMediaListView(mediaListView);
481 var current = mediaPageMgr.getPage(mediaListView.mediaList,
null, type);
484 while (pages.hasMoreElements()) {
485 page = pages.getNext().QueryInterface(
Ci.sbIMediaPageInfo);
486 if (page.contentUrl == current.contentUrl) {
487 if (!pages.hasMoreElements()) {
489 pages = mediaPageMgr.getAvailablePages(mediaListView.mediaList);
491 page = pages.getNext().QueryInterface(
Ci.sbIMediaPageInfo);
497 Components.reportError(
new Components.Exception(
498 "Failed to find any pages from media list view",
499 Components.results.NS_ERROR_NOT_AVAILABLE));
503 mediaPageMgr.setPage(mediaListView.mediaList, page);
504 browser.loadMediaList(mediaListView.mediaList,
521 _getMediaListViewForEvent:
function _getMediaListViewForEvent(
event )
523 var
target =
event.target;
529 if (target.mediaListView) {
530 return target.mediaListView;
532 if (target.currentMediaListView) {
533 return target.currentMediaListView;
538 target =
event.originalTarget;
539 if (target.mediaListView) {
540 return target.mediaListView;
542 if (target.currentMediaListView) {
543 return target.currentMediaListView;
547 if (
event.target.ownerDocument != document &&
window.gBrowser) {
548 target = gBrowser.getTabForDocument(
event.target.ownerDocument);
549 if (target && target.mediaListView) {
550 return target.mediaListView;
559 gSongbirdPlayerWindow._onLoadCallback =
560 function(e) { gSongbirdPlayerWindow.onLoad(e) };
561 window.addEventListener(
"load", gSongbirdPlayerWindow._onLoadCallback,
false);
var gSongbirdPlayerWindow
var gSongbirdWindowController
function movePlayerControls(aIsOnTop)
var PREF_PLAYER_CONTROL_LOCATION
function windowPlacementSanityChecks()
See if a window needs to be somehow "fixed" after it is opened.
function onUnload()
onUnload - called when the cover preview window unloads.