1 /* 	Name: Sound Module
  2 	Date: April 2011
  3 	Description: Main module for the sound functionality (using HTML5 Audio)
  4 	Dependencies: <none>
  5 	Children: <none> */
  6 	
  7 /* Properties GET FROM JSLINT */
  8 		
  9 /**
 10  * Creates an instance of the Sound module
 11  *
 12  * @constructor
 13  * @this {Sound}
 14  * @param {String} primaryid Primary sound ID from Audio element stored on page.
 15  * @see sound.js
 16  */
 17 function Sound(primaryid){
 18 	/**
 19 	* Sound primary audio ID. (From element stored in page).
 20 	*
 21 	* @type String
 22 	*/
 23 	Sound.primaryID = "";
 24 	
 25 	/**
 26 	* Sound alternate audio ID. (From element stored in page).
 27 	*
 28 	* @type String
 29 	*/
 30 	Sound.altID = "";
 31 
 32 	/**
 33 	 * Set primary sound ID from Audio element ID stored in page.
 34 	 * 
 35 	 * @param {String} pID ID of Audio element.
 36 	 * @this {Sound}
 37 	 */
 38 	this.setPrimarySound = function(pID){
 39 		Sound.primaryID = pID;
 40 	};
 41 	
 42 	// Setup intial sound on instantiation
 43 	this.setPrimarySound(primaryid);
 44 	
 45 	/**
 46 	 * Set alternative sound ID from Audio element ID stored in page.
 47 	 * 
 48 	 * @param {String} aID ID of Audio element.
 49 	 * @this {Sound}
 50 	 */
 51 	this.setAltSound = function(aID){
 52 		Sound.altID = aID;
 53 	}
 54 	
 55 	/**
 56 	 * Play sound from primary or alternate ID based on HTML5 sound support.
 57 	 * 
 58 	 * @this {Sound}
 59 	 */
 60 	this.play = function(){
 61 		var audioTest = document.createElement('audio');
 62 		if (audioTest.canPlayType('audio/mpeg;') == '' && !window.navigator.userAgent.toLowerCase().match("safari")){
 63 			var mySound = document.getElementById(Sound.altID);
 64 			mySound.play();
 65 			//alert("altSound");
 66 		} else if (audioTest.canPlayType('audio/mpeg;') == '' && window.navigator.userAgent.toLowerCase().match("safari")
 67 			&& !window.navigator.userAgent.toLowerCase().match("chrome")) {
 68 			alert("Sorry, HTML5 sound is not currently available for the Android platform.");
 69 		} else {
 70 			var mySound = document.getElementById(Sound.primaryID);
 71 			mySound.play();
 72 			//alert("primarySound");
 73 		}
 74 	};
 75 }