How to use the Javascript-controlled audio recorder

Step 1: assemble the files

Put these files together:

  1. swfobject.js file
  2. hiddenAudioControl.swf file
  3. your web page

Step 2: Edit the web page

Load the web page in a text editor, and make the following changes:

  1. Insert the swfobject.js file. Put this line in the head of the web page:

    <script type="text/javascript" src="swfobject.js"></script>

  2. Create a div to hold the swf file. Insert this HTML where you want the recorder to appear:

    <div id="flashcontent"></div>

  3. Write the javascript function to load the swf and give it values for the variables. Put this in the head of the web page:

    <script type="text/javascript">
    	var audioConsole;
    
    	window.onload = function(){
    		writeSWF();
    		if (navigator.appName.indexOf("Microsoft") != -1) {
    			audioConsole = window["embeddedSWF"];
    		} else {
    			audioConsole = document["embeddedSWF"];
    		}
    	}
    
    	function writeSWF(){
    		//var so = new SWFObject("hiddenAudioControl.swf", "embeddedSWF", "215", "150", "8", "#FFFFFF");
    		var so = new SWFObject("hiddenAudioControl.swf", "embeddedSWF", "0", "0", "8", "#FFFFFF");
    		so.addParam("wmode", "transparent");
    		so.addVariable("myServer","rtmp://red5.llc.msu.edu/dsh");
    		so.addVariable("mySound","sound0001");
    		so.write("flashcontent");
    	}
    	
    </script>
    

    Replace the text in red with the path to your application, and the name of your sound file. You can use scripting to make the name of the sound dynamic, like this:

    	function writeSWF(sndName){
    		var so = new SWFObject("audioControl.swf", "audiocontrol", "300", "150", "9", "#FF6600");
    		so.addParam("wmode", "transparent");
    		so.addVariable("myServer","rtmp://red5.llc.msu.edu/dsh");
    		so.addVariable("mySound",sndName);
    		so.write("flashcontent");		
    	}
    

    When you call the Javascript function, you pass the sound name as a parameter, like this:

    writeSWF("sound001");

  4. Add Javascript calls to the record, stop and playback functions

    	<a href="javascript:audioConsole.recAudio()">RECORD</a>
    	<a href="javascript:audioConsole.stopAudio()">STOP</a>
    	<a href="javascript:audioConsole.playAudio()">PLAY</a>
    

  5. Save the file, and load it in your browser.