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 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 11 12goog.provide('cvox.EarconsBackground'); 13 14goog.require('cvox.AbstractEarcons'); 15 16 17/** 18 * @constructor 19 * @extends {cvox.AbstractEarcons} 20 */ 21cvox.EarconsBackground = function() { 22 goog.base(this); 23 24 this.audioMap = new Object(); 25 if (localStorage['earcons'] === 'false') { 26 this.enabled = false; 27 } 28}; 29goog.inherits(cvox.EarconsBackground, cvox.AbstractEarcons); 30 31 32/** 33 * @return {string} The human-readable name of the earcon set. 34 */ 35cvox.EarconsBackground.prototype.getName = function() { 36 return 'ChromeVox earcons'; 37}; 38 39 40/** 41 * @return {string} The base URL for loading earcons. 42 */ 43cvox.EarconsBackground.prototype.getBaseUrl = function() { 44 return cvox.EarconsBackground.BASE_URL; 45}; 46 47 48/** 49 * @override 50 */ 51cvox.EarconsBackground.prototype.playEarcon = function(earcon) { 52 goog.base(this, 'playEarcon', earcon); 53 if (!this.enabled) { 54 return; 55 } 56 if (window['console']) { 57 window['console']['log']('Earcon ' + this.getEarconName(earcon)); 58 } 59 60 this.currentAudio = this.audioMap[earcon]; 61 if (!this.currentAudio) { 62 this.currentAudio = new Audio(chrome.extension.getURL(this.getBaseUrl() + 63 this.getEarconFilename(earcon))); 64 this.audioMap[earcon] = this.currentAudio; 65 } 66 try { 67 this.currentAudio.currentTime = 0; 68 } catch (e) { 69 } 70 if (this.currentAudio.paused) { 71 this.currentAudio.volume = 0.7; 72 this.currentAudio.play(); 73 } 74}; 75 76 77/** 78 * The base URL for loading eracons. 79 * @type {string} 80 */ 81cvox.EarconsBackground.BASE_URL = 'chromevox/background/earcons/'; 82