1 dump('entering util/sound.js\n');
3 if (typeof util == 'undefined') util = {};
4 util.sound = function (interval) {
8 /* We're going to turn this guy into a singleton, at least for a given window, and look for it in xulG */
9 if (! window.xulG) { window.xulG = {}; }
10 if (window.xulG._sound) { return window.xulG._sound; }
12 /* So we can queue up sounds and put a pause between them instead of having them trample over each other */
13 /* Limitation: interval only gets set once for a singleton */
17 JSAN.use('util.exec'); this._exec = new util.exec(); this._exec.timer( this._funcs, interval || 500 );
20 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
21 var SOUNDContractID = "@mozilla.org/sound;1";
22 var SOUNDIID = Components.interfaces.nsISound;
23 this.SOUND = Components.classes[SOUNDContractID].createInstance(SOUNDIID);
24 this.SOUND.init(); // not necessary, but helps avoid delays?
26 this.origin = location.pathname;
28 window.xulG._sound = this;
32 dump('error in util.sound constructor: ' + E + '\n');
37 util.sound.prototype = {
39 'xp_url_init' : function (aURL) {
41 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
42 var URLContractID = "@mozilla.org/network/standard-url;1";
43 var URLIID = Components.classes[URLContractID].createInstance( );
44 var URL = URLIID.QueryInterface(Components.interfaces.nsIURL);
50 alert('xp_url_init(): ' + E);
54 'play_url' : function(url) {
56 if (!url) { return; /* sound of silence */ }
60 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
61 JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
62 var url2 = obj.xp_url_init( data.server + url );
63 dump('SOUND: file = ' + url + '\n');
64 if (typeof data.no_sound == 'undefined' || data.no_sound == false || data.no_sound == 'false') {
67 obj._funcs.push( function() { obj.SOUND.play( url2 ); } );
69 obj.SOUND.play( url2 );
73 try { if (data.no_sound == 'undefined' || data.no_sound == false || data.no_sound == 'false') obj.SOUND.beep(); } catch(F) {
74 dump('beep(): ' + F + '\n');
76 dump('play_url(): ' + E + '\n');
80 'event' : function event(evt) {
81 var key = 'AUDIO_' + arguments.callee.name + '_' + evt.textcode;
82 dump('SOUND: key = ' + key + '\n');
83 this.play_url( urls[key] );
86 'good' : function good(e){
87 var key = 'AUDIO_' + arguments.callee.name;
88 dump('SOUND: key = ' + key + '\n');
89 this.play_url( urls[key] );
92 'bad' : function bad(e){
93 var key = 'AUDIO_' + arguments.callee.name;
94 dump('SOUND: key = ' + key + '\n');
95 this.play_url( urls[key] );
98 'horrible' : function horrible(e){
99 var key = 'AUDIO_' + arguments.callee.name;
100 dump('SOUND: key = ' + key + '\n');
101 this.play_url( urls[key] );
104 'circ_good' : function circ_good(e){
105 var key = 'AUDIO_' + arguments.callee.name;
106 dump('SOUND: key = ' + key + '\n');
107 this.play_url( urls[key] );
110 'circ_bad' : function circ_bad(e){
111 var key = 'AUDIO_' + arguments.callee.name;
112 dump('SOUND: key = ' + key + '\n');
113 this.play_url( urls[key] );
117 dump('exiting util/sound.js\n');