OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * @fileoverview Earcons library that uses the HTML5 Audio element to play back | 6 * @fileoverview Earcons library that uses the HTML5 Audio element to play back |
7 * auditory cues. | 7 * auditory cues. |
8 * | 8 * |
9 */ | 9 */ |
10 | 10 |
11 | 11 |
12 goog.provide('cvox.EarconsBackground'); | 12 goog.provide('cvox.ClassicEarcons'); |
13 | 13 |
14 goog.require('cvox.AbstractEarcons'); | 14 goog.require('cvox.AbstractEarcons'); |
15 | 15 |
16 | 16 |
17 /** | 17 /** |
18 * @constructor | 18 * @constructor |
19 * @extends {cvox.AbstractEarcons} | 19 * @extends {cvox.AbstractEarcons} |
20 */ | 20 */ |
21 cvox.EarconsBackground = function() { | 21 cvox.ClassicEarcons = function() { |
22 goog.base(this); | 22 goog.base(this); |
23 | 23 |
24 this.audioMap = new Object(); | 24 this.audioMap = new Object(); |
25 if (localStorage['earcons'] === 'false') { | 25 if (localStorage['earcons'] === 'false') { |
26 this.enabled = false; | 26 this.enabled = false; |
27 } | 27 } |
28 }; | 28 }; |
29 goog.inherits(cvox.EarconsBackground, cvox.AbstractEarcons); | 29 goog.inherits(cvox.ClassicEarcons, cvox.AbstractEarcons); |
30 | 30 |
31 | 31 |
32 /** | 32 /** |
33 * @return {string} The human-readable name of the earcon set. | 33 * @return {string} The human-readable name of the earcon set. |
34 */ | 34 */ |
35 cvox.EarconsBackground.prototype.getName = function() { | 35 cvox.ClassicEarcons.prototype.getName = function() { |
36 return 'ChromeVox earcons'; | 36 return 'ChromeVox earcons'; |
37 }; | 37 }; |
38 | 38 |
39 | 39 |
40 /** | 40 /** |
41 * @return {string} The base URL for loading earcons. | 41 * @return {string} The base URL for loading earcons. |
42 */ | 42 */ |
43 cvox.EarconsBackground.prototype.getBaseUrl = function() { | 43 cvox.ClassicEarcons.prototype.getBaseUrl = function() { |
44 return cvox.EarconsBackground.BASE_URL; | 44 return cvox.ClassicEarcons.BASE_URL; |
45 }; | 45 }; |
46 | 46 |
47 | 47 |
48 /** | 48 /** |
49 * @override | 49 * @override |
50 */ | 50 */ |
51 cvox.EarconsBackground.prototype.playEarcon = function(earcon) { | 51 cvox.ClassicEarcons.prototype.playEarcon = function(earcon) { |
52 goog.base(this, 'playEarcon', earcon); | 52 goog.base(this, 'playEarcon', earcon); |
53 if (!this.enabled) { | 53 if (!this.enabled) { |
54 return; | 54 return; |
55 } | 55 } |
56 if (window['console']) { | 56 console.log('Earcon ' + earcon); |
57 window['console']['log']('Earcon ' + earcon); | |
58 } | |
59 | 57 |
60 this.currentAudio = this.audioMap[earcon]; | 58 this.currentAudio = this.audioMap[earcon]; |
61 if (!this.currentAudio) { | 59 if (!this.currentAudio) { |
62 this.currentAudio = new Audio(chrome.extension.getURL(this.getBaseUrl() + | 60 this.currentAudio = new Audio(chrome.extension.getURL(this.getBaseUrl() + |
63 earcon + '.ogg')); | 61 earcon + '.ogg')); |
64 this.audioMap[earcon] = this.currentAudio; | 62 this.audioMap[earcon] = this.currentAudio; |
65 } | 63 } |
66 try { | 64 try { |
67 this.currentAudio.currentTime = 0; | 65 this.currentAudio.currentTime = 0; |
68 } catch (e) { | 66 } catch (e) { |
69 } | 67 } |
70 if (this.currentAudio.paused) { | 68 if (this.currentAudio.paused) { |
71 this.currentAudio.volume = 0.7; | 69 this.currentAudio.volume = 0.7; |
72 this.currentAudio.play(); | 70 this.currentAudio.play(); |
73 } | 71 } |
74 }; | 72 }; |
75 | 73 |
76 | 74 |
77 /** | 75 /** |
78 * The base URL for loading eracons. | 76 * The base URL for loading eracons. |
79 * @type {string} | 77 * @type {string} |
80 */ | 78 */ |
81 cvox.EarconsBackground.BASE_URL = 'chromevox/background/earcons/'; | 79 cvox.ClassicEarcons.BASE_URL = 'chromevox/background/earcons/'; |
OLD | NEW |