OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 /** |
| 6 * @fileoverview Earcons library that uses the HTML5 Audio element to play back |
| 7 * auditory cues. |
| 8 */ |
| 9 |
| 10 goog.provide('cvox.ChromeVoxEarcons'); |
| 11 |
| 12 goog.require('cvox.AbstractEarcons'); |
| 13 |
| 14 /** |
| 15 * @constructor |
| 16 * @extends {cvox.AbstractEarcons} |
| 17 */ |
| 18 cvox.ChromeVoxEarcons = function() { |
| 19 //Inherit AbstractEarcons |
| 20 cvox.AbstractEarcons.call(this); |
| 21 |
| 22 this.audioMap = new Object(); |
| 23 }; |
| 24 goog.inherits(cvox.ChromeVoxEarcons, cvox.AbstractEarcons); |
| 25 |
| 26 /** |
| 27 * @return {string} The human-readable name of the earcon set. |
| 28 */ |
| 29 cvox.ChromeVoxEarcons.prototype.getName = function() { |
| 30 return 'ChromeVox earcons'; |
| 31 }; |
| 32 |
| 33 /** |
| 34 * @return {string} The base URL for loading earcons. |
| 35 */ |
| 36 cvox.ChromeVoxEarcons.prototype.getBaseUrl = function() { |
| 37 return cvox.ChromeVoxEarcons.BASE_URL; |
| 38 }; |
| 39 |
| 40 /** |
| 41 * Plays the specified earcon sound. |
| 42 * @param {number} earcon The earcon index. |
| 43 */ |
| 44 cvox.ChromeVoxEarcons.prototype.playEarcon = function(earcon) { |
| 45 cvox.ChromeVoxEarcons.superClass_.playEarcon.call(this, earcon); |
| 46 this.currentAudio = this.audioMap[earcon]; |
| 47 if (!this.currentAudio) { |
| 48 var earconMap = this.getEarconMap(); |
| 49 if (!earconMap || !earconMap[earcon]) { |
| 50 return; |
| 51 } |
| 52 this.currentAudio = new Audio(this.getBaseUrl() + earconMap[earcon]); |
| 53 this.audioMap[earcon] = this.currentAudio; |
| 54 } |
| 55 try { |
| 56 this.currentAudio.currentTime = 0; |
| 57 } catch (e) { |
| 58 } |
| 59 if (this.currentAudio.paused) { |
| 60 this.currentAudio.play(); |
| 61 } |
| 62 }; |
| 63 |
| 64 /** |
| 65 * @return {Object} The earcon map which is lazy initialized. |
| 66 */ |
| 67 cvox.ChromeVoxEarcons.prototype.getEarconMap = function() { |
| 68 if (this.earconMap) { |
| 69 return this.earconMap; |
| 70 } |
| 71 this.earconMap = new Object(); |
| 72 this.earconMap[cvox.AbstractEarcons.ALERT_MODAL] = 'alert_modal.ogg'; |
| 73 this.earconMap[cvox.AbstractEarcons.ALERT_NONMODAL] = |
| 74 'alert_nonmodal.ogg'; |
| 75 this.earconMap[cvox.AbstractEarcons.BULLET] = 'bullet.ogg'; |
| 76 this.earconMap[cvox.AbstractEarcons.BUSY_PROGRESS_LOOP] = |
| 77 'busy_progress_loop.ogg'; |
| 78 this.earconMap[cvox.AbstractEarcons.BUSY_WORKING_LOOP] = |
| 79 'busy_working_loop.ogg'; |
| 80 this.earconMap[cvox.AbstractEarcons.BUTTON] = 'button.ogg'; |
| 81 this.earconMap[cvox.AbstractEarcons.CHECK_OFF] = 'check_off.ogg'; |
| 82 this.earconMap[cvox.AbstractEarcons.CHECK_ON] = 'check_on.ogg'; |
| 83 this.earconMap[cvox.AbstractEarcons.COLLAPSED] = 'collapsed.ogg'; |
| 84 this.earconMap[cvox.AbstractEarcons.EDITABLE_TEXT] = 'editable_text.ogg'; |
| 85 this.earconMap[cvox.AbstractEarcons.ELLIPSIS] = 'ellipsis.ogg'; |
| 86 this.earconMap[cvox.AbstractEarcons.EXPANDED] = 'expanded.ogg'; |
| 87 this.earconMap[cvox.AbstractEarcons.FONT_CHANGE] = 'font_change.ogg'; |
| 88 this.earconMap[cvox.AbstractEarcons.INVALID_KEYPRESS] = |
| 89 'invalid_keypress.ogg'; |
| 90 this.earconMap[cvox.AbstractEarcons.LINK] = 'link.ogg'; |
| 91 this.earconMap[cvox.AbstractEarcons.LISTBOX] = 'listbox.ogg'; |
| 92 this.earconMap[cvox.AbstractEarcons.NEW_MAIL] = 'new_mail.ogg'; |
| 93 this.earconMap[cvox.AbstractEarcons.OBJECT_CLOSE] = 'object_close.ogg'; |
| 94 this.earconMap[cvox.AbstractEarcons.OBJECT_DELETE] = 'object_delete.ogg'; |
| 95 this.earconMap[cvox.AbstractEarcons.OBJECT_DESELECT] = |
| 96 'object_deselect.ogg'; |
| 97 this.earconMap[cvox.AbstractEarcons.OBJECT_OPEN] = 'object_open.ogg'; |
| 98 this.earconMap[cvox.AbstractEarcons.OBJECT_SELECT] = 'object_select.ogg'; |
| 99 this.earconMap[cvox.AbstractEarcons.PARAGRAPH_BREAK] = |
| 100 'paragraph_break.ogg'; |
| 101 this.earconMap[cvox.AbstractEarcons.SEARCH_HIT] = 'search_hit.ogg'; |
| 102 this.earconMap[cvox.AbstractEarcons.SEARCH_MISS] = 'search_miss.ogg'; |
| 103 this.earconMap[cvox.AbstractEarcons.SECTION] = 'section.ogg'; |
| 104 this.earconMap[cvox.AbstractEarcons.TASK_SUCCESS] = 'task_success.ogg'; |
| 105 this.earconMap[cvox.AbstractEarcons.WRAP] = 'wrap.ogg'; |
| 106 this.earconMap[cvox.AbstractEarcons.WRAP_EDGE] = 'wrap_edge.ogg'; |
| 107 |
| 108 return this.earconMap; |
| 109 }; |
| 110 |
| 111 /** |
| 112 * The base URL for loading eracons. |
| 113 * @type {string} |
| 114 */ |
| 115 cvox.ChromeVoxEarcons.BASE_URL = 'earcons/'; |
OLD | NEW |