audio-play-pause

by sjmcpherson

HTML

<p><a class="play" key="wash-song1_2" target="player"><IMG SRC="http://designlab360.org/fhi/splash/dev2/images/arrow-right.png" BORDER=0 WIDTH=30 HEIGHT=29></a></p>    
<p><a class="play" key="wash-song2_2" target="player"><IMG SRC="http://designlab360.org/fhi/splash/dev2/images/arrow-right.png" BORDER=0 WIDTH=30 HEIGHT=29></a></p>

JavaScript

$(".play").on('click',function(){
     var key = $(this).attr('key');     
     EvalSound(key);
 });

var thissound = new Audio();
var currentKey;
	function EvalSound(key) {


        
   if(currentKey !== key)
 	 thissound.src = "http://designlab360.org/fhi/splash/dev2/audio/" + key + ".mp3";      
     currentKey = key;
        
	 if (thissound.paused)
				thissound.play();
		else
			thissound.pause();
			thissound.currentTime = 0;
			 currentPlayer = thissound;
        
        
        
        
	}