<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="http://feedproxy.google.com/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feedproxy.google.com/~d/styles/itemcontent.css"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>The Tech Labs » Sound</title>
	
	<link>http://www.thetechlabs.com</link>
	<description>Adobe Air, Flash and Flex Tutorials</description>
	<pubDate>Thu, 23 Oct 2008 22:58:12 +0000</pubDate>
	<generator>http://wordpress.org/?v=abc</generator>
	<language>en</language>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feedproxy.google.com/TheTechLabs_sound" type="application/rss+xml" /><item>
		<title>Create a AS3 MP3 Player with papervision3d spectrum display</title>
		<link>http://feedproxy.google.com/~r/TheTechLabs_sound/~3/dXzgeRvapZs/</link>
		<comments>http://www.thetechlabs.com/3d/create-a-as3-mp3-player-with-papervision3d-spectrum-display/#comments</comments>
		<pubDate>Sun, 06 Jul 2008 00:22:06 +0000</pubDate>
		<dc:creator>Rafael Nuenlist</dc:creator>
		
		<category><![CDATA[3D]]></category>

		<category><![CDATA[Flash]]></category>

		<category><![CDATA[Sound]]></category>

		<category><![CDATA[adobe flash]]></category>

		<category><![CDATA[as3]]></category>

		<category><![CDATA[mp3 player]]></category>

		<category><![CDATA[papervision 3d]]></category>

		<category><![CDATA[spectrum]]></category>

		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.thetechlabs.com/?p=58</guid>
		<description><![CDATA[<p>As we&#8217;ve already promised you, here&#8217;s the tutorial about how to create a 3d spectrum display from a sound file with papervision3d and flash.<br />
On this tutorial, we&#8217;ll focus on the 3d part. If you&#8217;re not comfortable with the SoundMixer.computeSpectrum method then you should read the previous tutorial.</p>
<small><em>posted in <a href="http://www.thetechlabs.com/category/3d/">3D</a> by Rafael Nuenlist <a href="http://www.thetechlabs.com/3d/create-a-as3-mp3-player-with-papervision3d-spectrum-display/#comments">Leave A Comment</a><br />&copy;2008 <a href="http://www.thetechlabs.com">The Tech Labs</a>. All Rights Reserved.</em></small>]]></description>
			<content:encoded><![CDATA[<p>As we&#8217;ve already promised you, here&#8217;s the tutorial about how to create a 3d spectrum display from a sound file with papervision3d and flash.<br />
On this tutorial, we&#8217;ll focus on the 3d part. If you&#8217;re not comfortable with the SoundMixer.computeSpectrum method then you should read the <a title="Create a AS3 / Flash 9 MP3 Player with spectrum display" href="http://www.thetechlabs.com/sound/create-a-as3-flash-9-mp3-player-with-spectrum-display/"  target="_blank">previous tutorial</a>.<br />
So, let&#8217;s start with the fun.</p>
<h3>Requirements</h3>
<p><strong>Adobe Flash CS3</strong></p>
<p><a title="Try / buy" onclick="javascript:pageTracker._trackPageview('/outbound/article/http://www.adobe.com/products/flash/');" href="http://www.adobe.com/products/flash/" onclick="javascript:pageTracker._trackPageview('oclicks/http://www.adobe.com/products/flash/');" target="_blank">Try / Buy</a></p>
<p><strong>Source Files</strong></p>
<p><a title="Download Source Files" onclick="javascript:pageTracker._trackPageview('/downloads/tutorials/files/flash/fcarrera/flickrsearchengine/flickrsearchengine_sfiles.zip');" href="http://www.thetechlabs.com/tutorials/files/flash/rnunlist/pv3d-spectrum.zip" onclick="javascript:pageTracker._trackPageview('downloads/tutorials/files/flash/rnunlist/pv3d-spectrum.zip');" target="_self">Download</a></p>
<h3>Getting Started</h3>
<p>For this demo application, we&#8217;ve used the latest version of papervision3d with the code name GreatWhite.<br />
First of all, we need to include the papervision3d stuff.</p>
<pre>import org.papervision3d.cameras.Camera3D;
import org.papervision3d.scenes.Scene3D;
import org.papervision3d.view.Viewport3D;
import org.papervision3d.render.BasicRenderEngine;
import org.papervision3d.objects.primitives.Cube;
import org.papervision3d.materials.ColorMaterial;
import org.papervision3d.materials.utils.MaterialsList;
</pre>
<p align="justify">These are all the classes we need for our application. The Camera3D class enables you to focus on a 3d object and zoom to it. Scene3D is a container that holds all 3d objects. The Viewport will be added to the main stage and is like a video screen that shows the result. Another important class is the BasicRenderEngine which renders all the objects from the scene with the current camera settings and outputs the result to the viewport. Papervision comes with different types of objects, but for our example we&#8217;ll only need the cube. And finally there are the materials which can be set to the objects. This is how papervision basically works.</p>
<p>Then we to set some constants for the sound channel</p>
<pre>const CHANNELS_PER_DIRECTION:int= 256;
const CUBES_PER_CHANNEL:int		= 8;
const CHANNEL_STEPS:int			= Math.floor(CHANNELS_PER_DIRECTION / CUBES_PER_CHANNEL);
</pre>
<p>Next thing to do is to set the papervision variables</p>
<pre>var viewport:Viewport3D;
var scene:Scene3D;
var camera:Camera3D;
var cube:Cube;
var renderer:BasicRenderEngine;
</pre>
<p>To keep a reference of each cube, we need to create 2 arrays. For each sound channel (left, right)</p>
<pre>var cubesLeftChannel:Array		= new Array();
var cubesRightChannel:Array		= new Array();
</pre>
<p>At the end, we want to swing our camera from left to right and	vice versa. To know in which direction we&#8217;re currently moving, we need to set a flag:</p>
<pre>var bolAnimationForward:Boolean 	= true;
</pre>
<p>The next part is the same as in the previous tutorial. We create a new sound object and a url request for requesting the mp3 file. SndBytes will hold the current spectrum data.</p>
<pre>var sndObject:Sound			= new Sound();
var reqObject:URLRequest 		= new URLRequest("so-deep.ram2000.mp3");
var sndBytes:ByteArray			= new ByteArray();
</pre>
<p>So, the next step will be the initializing of our 3d stuff, then loading the soundfile and finally creating the render loop.<br />
First of all, we create a new viewport and add it to the stage. The third parameter tells the viewport to use the whole width and height of the swf file for displaying the 3d objects.</p>
<pre>viewport = new Viewport3D(0, 0, true);
addChild(viewport);
</pre>
<p>Then we create a new basic render engine and a scene which holds the 3d objects</p>
<pre>renderer = new BasicRenderEngine();
scene = new Scene3D();
</pre>
<p>Our cubes will need a material. We create a blue one for cubes that are displaying the left channel and a green material for the other ones. You can easily change the colors for each side using hex values.</p>
<pre>var blueMaterial:MaterialsList = new MaterialsList(
	{
		front:  new ColorMaterial(0x0066FF),
		back:   new ColorMaterial(0x0066FF),
		right:  new ColorMaterial(0x0046B0),
		left:   new ColorMaterial(0x0046B0),
		top:    new ColorMaterial(0x1171FF),
		bottom: new ColorMaterial(0x1171FF)
	}
);

var greenMaterial:MaterialsList = new MaterialsList(
	{
		front:  new ColorMaterial(0x00CC00),
		back:   new ColorMaterial(0x00CC00),
		right:  new ColorMaterial(0x009F00),
		left:   new ColorMaterial(0x009F00),
		top:    new ColorMaterial(0x00CC00),
		bottom: new ColorMaterial(0x00CC00)
	}
);
</pre>
<p>Now we need to create the cubes for the left channel, position them correctly on the x-axis, keep a reference in the array and add them to the scene</p>
<pre>for(var i = 0; i &lt; CUBES_PER_CHANNEL; i++) {
	cube = new Cube(blueMaterial, 12, 50, 400);
	cube.x = i * 50;
	cubesLeftChannel.push(cube);
	scene.addChild(cube);
}
</pre>
<p>The same procedure for the cubes standing for the right channel but with the green material and we place them between the green ones.</p>
<pre>for(i = 0; i &lt; CUBES_PER_CHANNEL; i++) {
	cube = new Cube(greenMaterial, 12, 50);
	cube.x = (i * 50) + 25;
	cubesRightChannel.push(cube);
	scene.addChild(cube);
}
</pre>
<p>Finally we create a new camera, set the target to the cube in the middle, adjust the zoom and move the start position a bit to the upper left</p>
<pre>camera = new Camera3D();
camera.zoom = 11;
camera.target = cubesRightChannel[CUBES_PER_CHANNEL / 2 - 1] as Cube;
camera.x -= 400;
camera.y += 300;
</pre>
<p>Now we&#8217;re finished with creating all the necessary 3d stuff. Next thing to do is loading a sample mp3 file which is quite easy. We just load the url request we&#8217;ve created bevore and play the file.</p>
<pre>sndObject.load(reqObject);
sndObject.play();
</pre>
<p>The only thing left to do is the render loop. This loop will be executed on enter frame, in our case 60 times per second. First, we compute the spectrum and put the result in the defined byte array.</p>
<pre>SoundMixer.computeSpectrum(sndBytes);
</pre>
<p>Then we set the right position for the byte array pointer, read the float value and assign it to the current cube scaleY value. Like this, the cubes will be resized according to the spectrum. After the end of the first loop, we repeat the procedure for the right channel cubes</p>
<pre>for(var i = 0; i &lt; CUBES_PER_CHANNEL; i++) {
	var myCube:Cube = cubesLeftChannel[i] as Cube;
	sndBytes.position = CHANNEL_STEPS * 4 * i;
	myCube.scaleY =  sndBytes.readFloat();
}
for(i = 0; i &lt; CUBES_PER_CHANNEL; i++) {
	myCube = cubesRightChannel[i] as Cube;
	sndBytes.position = 1024 + (CHANNEL_STEPS * 4 * i);
	myCube.scaleY = sndBytes.readFloat();
}
</pre>
<p>To swing our camera a bit, we increase and decrease it&#8217;s x value</p>
<pre>if(bolAnimationForward) {
	camera.x += 4;
	if(camera.x &gt; 800)
		bolAnimationForward = false;
} else {
	camera.x -= 4;
	if(camera.x &lt; -400)
		bolAnimationForward = true;
}
</pre>
<p>And now we need to tell the render engine to render the current scene, camera and viewport</p>
<pre>renderer.renderScene(scene, camera, viewport);
</pre>
<p>That was already the whole trick. You can also try rendering other materials and different objects. These were just the basics about papervision3d. We hope you enjoyed reading this tutorial. Any feedbacks and questions are welcome.</p>
<p>In the final you will get this:</p>
<p><a href="http://www.thetechlabs.com/tutorials/files/flash/rnunlist/pv3d-spectrum/pv3d-spectrum.html" ><img class="aligncenter size-full wp-image-57" title="Create a AS3 MP3 Player with papervision3d spectrum display" src="http://www.thetechlabs.com/wp-content/uploads/2008/07/create-a-as3-mp3-player-with-papervision3d-spectrum-display.jpg" alt="Create a AS3 MP3 Player with papervision3d spectrum display" width="500" height="180" /></a></p>
<p>Full code with comments</p>
<pre>// Import Papervision3D
import org.papervision3d.cameras.Camera3D;
import org.papervision3d.scenes.Scene3D;
import org.papervision3d.view.Viewport3D;
import org.papervision3d.render.BasicRenderEngine;
import org.papervision3d.objects.primitives.Cube;
import org.papervision3d.materials.ColorMaterial;
import org.papervision3d.materials.utils.MaterialsList;

// constants
const CHANNELS_PER_DIRECTION:int= 256;
const CUBES_PER_CHANNEL:int		= 8;
const CHANNEL_STEPS:int			= Math.floor(CHANNELS_PER_DIRECTION / CUBES_PER_CHANNEL);

// papervision vars
var viewport:Viewport3D;
var scene:Scene3D;
var camera:Camera3D;
var cube:Cube;
var renderer:BasicRenderEngine;

// arrays holding references to cubes for each channel
var cubesLeftChannel:Array		= new Array();
var cubesRightChannel:Array		= new Array();
// animation flag
var bolAnimationForward:Boolean = true;

// sound vars
var sndObject:Sound				= new Sound();
var reqObject:URLRequest 		= new URLRequest("so-deep.ram2000.mp3");
var sndBytes:ByteArray			= new ByteArray();

// INIT
function init():void {
	init3D();
	initSound();
	// add event listener for render loop
	addEventListener(Event.ENTER_FRAME, renderLoop);
}

// init3d
function init3D():void {
	// Create viewport
	viewport = new Viewport3D(0, 0, true);
	// add viewport to stage
	addChild(viewport);

	// create basic render engine
	renderer = new BasicRenderEngine();

	// Create scene
	scene = new Scene3D();

	// blue cube material
	var blueMaterial:MaterialsList = new MaterialsList(
		{
			front:  new ColorMaterial(0x0066FF),
			back:   new ColorMaterial(0x0066FF),
			right:  new ColorMaterial(0x0046B0),
			left:   new ColorMaterial(0x0046B0),
			top:    new ColorMaterial(0x1171FF),
			bottom: new ColorMaterial(0x1171FF)
		}
	);

	// green cube material
	var greenMaterial:MaterialsList = new MaterialsList(
		{
			front:  new ColorMaterial(0x00CC00),
			back:   new ColorMaterial(0x00CC00),
			right:  new ColorMaterial(0x009F00),
			left:   new ColorMaterial(0x009F00),
			top:    new ColorMaterial(0x00CC00),
			bottom: new ColorMaterial(0x00CC00)
		}
	);

	// create cubes for left channel
	for(var i = 0; i &lt; CUBES_PER_CHANNEL; i++) {
		cube = new Cube(blueMaterial, 12, 50, 400);
		cube.x = i * 50;
		cubesLeftChannel.push(cube);
		scene.addChild(cube);
	}
	//create cubes for the right channel
	for(i = 0; i &lt; CUBES_PER_CHANNEL; i++) {
		cube = new Cube(greenMaterial, 12, 50);
		cube.x = (i * 50) + 25;
		cubesRightChannel.push(cube);
		scene.addChild(cube);
	}

	// create camera
	camera = new Camera3D();
	// set camera zoom
	camera.zoom = 11;
	// set cube in the center as camera target
	camera.target = cubesRightChannel[CUBES_PER_CHANNEL / 2 - 1] as Cube;
	// camera start position
	camera.x -= 400;
	camera.y += 300;
}

function initSound():void {
	// load mp3 file and play it
	sndObject.load(reqObject);
	sndObject.play();
}

// render loop function
function renderLoop(e:Event):void
{
	// compute spectrum and put result in byte array
	SoundMixer.computeSpectrum(sndBytes);

	//
	// LEFT CHANNEL CUBES
	for(var i = 0; i &lt; CUBES_PER_CHANNEL; i++) {
		var myCube:Cube = cubesLeftChannel[i] as Cube;
		// get the right positions for the byte array
		sndBytes.position = CHANNEL_STEPS * 4 * i;
		// resize current cube
		myCube.scaleY =  sndBytes.readFloat();
	}
	//
	// RIGHT CHANNEL CUBES
	for(i = 0; i &lt; CUBES_PER_CHANNEL; i++) {
		myCube = cubesRightChannel[i] as Cube;
		// get the right positions for the byte array
		sndBytes.position = 1024 + (CHANNEL_STEPS * 4 * i);
		// resize current cube
		myCube.scaleY = sndBytes.readFloat();
	}

	// swing camera
	if(bolAnimationForward) {
		camera.x += 4;
		if(camera.x &gt; 800)
			bolAnimationForward = false;
	} else {
		camera.x -= 4;
		if(camera.x &lt; -400)
			bolAnimationForward = true;
	}

	// render current scene
	renderer.renderScene(scene, camera, viewport);
}

init();
</pre>
<p class="addtoany_share_save_container">
    <a class="a2a_dd addtoany_share_save" onmouseover="a2a_show_dropdown(this)" onmouseout="a2a_onMouseOut_delay()" href="http://www.addtoany.com/share_save?sitename=The%20Tech%20Labs&amp;siteurl=http%3A%2F%2Fwww.thetechlabs.com%2F&amp;linkname=Create%20a%20AS3%20MP3%20Player%20with%20papervision3d%20spectrum%20display&amp;linkurl=http%3A%2F%2Fwww.thetechlabs.com%2F3d%2Fcreate-a-as3-mp3-player-with-papervision3d-spectrum-display%2F" onclick="javascript:pageTracker._trackPageview('oclicks/http://www.addtoany.com/share_save?sitename=The%20Tech%20Labs&amp;siteurl=http%3A%2F%2Fwww.thetechlabs.com%2F&amp;linkname=Create%20a%20AS3%20MP3%20Player%20with%20papervision3d%20spectrum%20display&amp;linkurl=http%3A%2F%2Fwww.thetechlabs.com%2F3d%2Fcreate-a-as3-mp3-player-with-papervision3d-spectrum-display%2F');"><img src="http://www.thetechlabs.com/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" alt="Share/Save/Bookmark"/></a>

	</p><img src="http://feedproxy.google.com/~r/TheTechLabs_sound/~4/dXzgeRvapZs" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.thetechlabs.com/3d/create-a-as3-mp3-player-with-papervision3d-spectrum-display/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.thetechlabs.com/3d/create-a-as3-mp3-player-with-papervision3d-spectrum-display/</feedburner:origLink></item>
		<item>
		<title>Create a AS3 / Flash 9 MP3 Player with spectrum display</title>
		<link>http://feedproxy.google.com/~r/TheTechLabs_sound/~3/CoLzHj-Ka_8/</link>
		<comments>http://www.thetechlabs.com/sound/create-a-as3-flash-9-mp3-player-with-spectrum-display/#comments</comments>
		<pubDate>Wed, 28 May 2008 22:25:30 +0000</pubDate>
		<dc:creator>Rafael Nuenlist</dc:creator>
		
		<category><![CDATA[Flash]]></category>

		<category><![CDATA[Interfaces]]></category>

		<category><![CDATA[Sound]]></category>

		<category><![CDATA[how-to]]></category>

		<category><![CDATA[mp3]]></category>

		<category><![CDATA[spectrum]]></category>

		<category><![CDATA[tutorial]]></category>

		<category><![CDATA[webdesign]]></category>

		<guid isPermaLink="false">http://thetechlabs.com/?p=15</guid>
		<description><![CDATA[<p>In this tutorial, we’re going to build a Flash mp3 player with a spectrum analyzer written in AS3.<br />
We’ll focus on the spectrum analyzer and build just the basic functionality for the player itself.</p>
<small><em>posted in <a href="http://www.thetechlabs.com/category/flash/">Flash</a> by Rafael Nuenlist <a href="http://www.thetechlabs.com/sound/create-a-as3-flash-9-mp3-player-with-spectrum-display/#comments">Leave A Comment</a><br />&copy;2008 <a href="http://www.thetechlabs.com">The Tech Labs</a>. All Rights Reserved.</em></small>]]></description>
			<content:encoded><![CDATA[<p>In this tutorial, we’re going to build a Flash mp3 player with a spectrum analyzer written in AS3.</p>
<p>We’ll focus on the spectrum analyzer and build just the basic functionality for the player itself.</p>
<p>Actionscript 3 has a new class called SoundMixer which gives you global sound control in the SWF file. It comes with the computeSpectrum method that takes a snapshot of the current sound wave and places it into the specified ByteArray object. The values are formatted as floating-point values, in the range -1.0 to 1.0. There are in total 512 values. Half of them for the right and left channel.</p>
<p>With these values you can easily create a visual spectrum. Let’s take a closer look at our renderSpectrum function, which is automatically called, when Flash enters a new frame.</p>
<p>First of all, we set a reference to the spectrum graphics:</p>
<pre>function renderSpectrum(e:Event):void
{
var g:Graphics = this.mcMp3Player.spectrum.graphics;</pre>
<p>Next, we compute the spectrum in the byte array “sndBytes”:</p>
<pre>SoundMixer.computeSpectrum(sndBytes);</pre>
<p>And then comes the most important part, visualizing the spectrum that is. We clear all the graphics and set a new line style and fill and move our drawing pointer to the middle left position.</p>
<p>Next, we create a number “n” which will contain the multiplied number from the maximum height of the spectrum and the current float number.</p>
<p>To create the curves, we iterate 256 times (which represents the left channel values) and read the current  float numbers from the byte array. Note that reading a value from a byte array will automatically set the pointer position to the next value.</p>
<p>As mentioned before, we multiply the float number with the maximum height and set it to “n”. In our case the value will be between 75 and -75 depending on what values we get from the byte array. To draw the line we use “i * 2″ for the x-coordinate and “SPECTRUM_HEIGHT - n” for the y-coordinate. This will result in a nice wave shape. We only need to set the end point for the line and end the fill instruction.</p>
<p>For the right channel it’s the same procedure, except that we take the last 256 values from the byte array.</p>
<pre>g.clear();
g.lineStyle(0, SPECTRUM_LEFT_LINE_COLOR);
g.beginFill(SPECTRUM_LEFT_FILL_COLOR, SPECTRUM_LEFT_FILL_ALPHA);
g.moveTo(0, SPECTRUM_HEIGHT);
var n:Number = 0;
for (var i:int = 0; i &lt; CHANNEL_LENGTH; i++) {
n = (sndBytes.readFloat() * SPECTRUM_HEIGHT);
g.lineTo(i * 2, SPECTRUM_HEIGHT - n);
}
g.lineTo(CHANNEL_LENGTH * 2, SPECTRUM_HEIGHT);
g.endFill();</pre>
<p>As you can see, it’s very easy to create a nice little spectrum. There are many other amazing spectrum analyzer out there which you should check out.</p>
<p>Here is the full code of this mp3 player, with the constants and vars, where you set the animation parameters:</p>
<pre>// spectrum constants
const SPECTRUM_HEIGHT:int                 = 75;
const CHANNEL_LENGTH:int                 = 256;
const SPECTRUM_LEFT_FILL_COLOR:uint        = 0x5FDEFE;
const SPECTRUM_LEFT_FILL_ALPHA:Number    = 0.5;
const SPECTRUM_LEFT_LINE_COLOR:uint        = 0x013643;
const SPECTRUM_RIGHT_FILL_COLOR:uint    = 0xBFF075;
const SPECTRUM_RIGHT_FILL_ALPHA:Number    = 0.5;
const SPECTRUM_RIGHT_LINE_COLOR:uint    = 0x4A730D;
// vars
var sndObject:Sound                = new Sound();
var chaObject:SoundChannel        = new SoundChannel() ;
var sndTransform:SoundTransform    = new SoundTransform();
var reqObject:URLRequest         = new URLRequest("so-deep.ram2000.mp3");
var sndBytes:ByteArray            = new ByteArray();
var intPosition:int             = 0;
var bolStop:Boolean                = true;
function initMP3Player():void {
// set event listeners
addEventListener(Event.ENTER_FRAME, renderSpectrum);
addEventListener(Event.ENTER_FRAME, calcProgress);
this.mcMp3Player.btnStop.addEventListener(MouseEvent.CLICK, stopPlayback);
this.mcMp3Player.btnPause.addEventListener(MouseEvent.CLICK, pausePlayback);
this.mcMp3Player.btnPlay.addEventListener(MouseEvent.CLICK, startPlayback);
this.mcMp3Player.btnMute.addEventListener(MouseEvent.CLICK, mutePlayback);
this.mcMp3Player.btnUnmute.addEventListener(MouseEvent.CLICK, unmutePlayback);
this.mcMp3Player.progress.addEventListener(MouseEvent.CLICK, setNewProgress);
// use hand cursor for progress bar
this.mcMp3Player.progress.buttonMode = true;
this.mcMp3Player.btnPause.visible    = false;
this.mcMp3Player.btnUnmute.visible    = false;
}
function stopPlayback(e:MouseEvent):void {
chaObject.stop();
sndObject = new Sound();
bolStop = true;
intPosition = 0;
this.mcMp3Player.btnPlay.visible    = true;
this.mcMp3Player.btnPause.visible    = false;
}
function pausePlayback(e:MouseEvent):void {
this.mcMp3Player.btnPlay.visible    = true;
this.mcMp3Player.btnPause.visible    = false;
playSound(false);
}
function startPlayback(e:MouseEvent):void {
this.mcMp3Player.btnPlay.visible    = false;
this.mcMp3Player.btnPause.visible    = true;
playSound();
}
function mutePlayback(e:MouseEvent):void {
this.mcMp3Player.btnMute.visible    = false;
this.mcMp3Player.btnUnmute.visible    = true;
setVolume(0);
}
function unmutePlayback(e:MouseEvent):void {
this.mcMp3Player.btnMute.visible    = true;
this.mcMp3Player.btnUnmute.visible    = false;
setVolume(1);
}
function setNewProgress(e:MouseEvent):void {
var p:int = sndObject.length * e.currentTarget.mouseX / 220;
chaObject.stop();
chaObject = sndObject.play(p);
this.mcMp3Player.btnPlay.visible    = false;
this.mcMp3Player.btnPause.visible    = true;
}
function playSound(bolPlay:Boolean = true):void {
if(bolPlay) {
if(bolStop) {
// load mp3 file if playback has been stopped
sndObject.load(reqObject);
bolStop = false;
} else {
intPosition = chaObject.position;
}
chaObject = sndObject.play(intPosition);
} else {
chaObject.stop();
}
}
function setVolume(intVolume:int = 1):void {
sndTransform.volume = intVolume;
chaObject.soundTransform = sndTransform;
}
function calcProgress(e:Event):void {
var p:MovieClip = this.mcMp3Player.progress.mcProgressFill;
var w:int        = Math.round( 220 * chaObject.position / sndObject.length);
p.width         = w;
}
function renderSpectrum(e:Event):void
{
// set a reference to the spectrum graphics
var g:Graphics = this.mcMp3Player.spectrum.graphics;
// compute spectrum in byte array sndBytes
SoundMixer.computeSpectrum(sndBytes);
/*
*    LEFT CHANNEL
*/
g.clear();
g.lineStyle(0, SPECTRUM_LEFT_LINE_COLOR);
g.beginFill(SPECTRUM_LEFT_FILL_COLOR, SPECTRUM_LEFT_FILL_ALPHA);
g.moveTo(0, SPECTRUM_HEIGHT);
var n:Number = 0;
for (var i:int = 0; i &lt; CHANNEL_LENGTH; i++) {
n = (sndBytes.readFloat() * SPECTRUM_HEIGHT);
g.lineTo(i * 2, SPECTRUM_HEIGHT - n);
}
g.lineTo(CHANNEL_LENGTH * 2, SPECTRUM_HEIGHT);

g.endFill();
/*
*    RIGHT CHANNEL
*/
g.lineStyle(0, SPECTRUM_RIGHT_LINE_COLOR);
g.beginFill(SPECTRUM_RIGHT_FILL_COLOR, SPECTRUM_RIGHT_FILL_ALPHA);
g.moveTo(CHANNEL_LENGTH * 2, SPECTRUM_HEIGHT);
for (i = CHANNEL_LENGTH; i &gt; 0; i--) {
n = (sndBytes.readFloat() * SPECTRUM_HEIGHT);
g.lineTo(i * 2, SPECTRUM_HEIGHT - n);
}
g.lineTo(0, SPECTRUM_HEIGHT);
g.endFill();
}
initMP3Player();</pre>
<p>So, we’ve already reached the end of our lesson and we hope, that you enjoyed it!</p>
<p>Be sure to check back soon as we’ll take the spectrum analyzer to 3d!</p>
<p><a title="Download Source" href="http://thetechlabs.com/flashenabledblog/tutorials/mp3player.zip" onclick="javascript:pageTracker._trackPageview('downloads/flashenabledblog/tutorials/mp3player.zip');" target="_self">Download Support files</a></p>
<p class="addtoany_share_save_container">
    <a class="a2a_dd addtoany_share_save" onmouseover="a2a_show_dropdown(this)" onmouseout="a2a_onMouseOut_delay()" href="http://www.addtoany.com/share_save?sitename=The%20Tech%20Labs&amp;siteurl=http%3A%2F%2Fwww.thetechlabs.com%2F&amp;linkname=Create%20a%20AS3%20%2F%20Flash%209%20MP3%20Player%20with%20spectrum%20display&amp;linkurl=http%3A%2F%2Fwww.thetechlabs.com%2Fsound%2Fcreate-a-as3-flash-9-mp3-player-with-spectrum-display%2F" onclick="javascript:pageTracker._trackPageview('oclicks/http://www.addtoany.com/share_save?sitename=The%20Tech%20Labs&amp;siteurl=http%3A%2F%2Fwww.thetechlabs.com%2F&amp;linkname=Create%20a%20AS3%20%2F%20Flash%209%20MP3%20Player%20with%20spectrum%20display&amp;linkurl=http%3A%2F%2Fwww.thetechlabs.com%2Fsound%2Fcreate-a-as3-flash-9-mp3-player-with-spectrum-display%2F');"><img src="http://www.thetechlabs.com/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" alt="Share/Save/Bookmark"/></a>

	</p><img src="http://feedproxy.google.com/~r/TheTechLabs_sound/~4/CoLzHj-Ka_8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.thetechlabs.com/sound/create-a-as3-flash-9-mp3-player-with-spectrum-display/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.thetechlabs.com/sound/create-a-as3-flash-9-mp3-player-with-spectrum-display/</feedburner:origLink></item>
	</channel>
</rss>
