
Actionscript: Audio Visualizer & Player
Yeah, I know it's a dead language, but it's close enough to JavaScript and C# someone might get a use from it. That and it was a lot of fun to make, so whatever, it's my website, back off honkey.
Some code I wrote a while ago for the media player/visualizer for Stan Bush’s Facebook App. I grew another grey hair just from typing that.
stanwidget.as
package
{
// -- IMPORT
// my scripts
import com.drpunchlogic.*;
// tweening
import com.greensock.*;
import com.greensock.easing.*;
// -- flash imoports
// display
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.display.Stage;
// events
import flash.events.MouseEvent;
import flash.events.Event;
import flash.events.ProgressEvent;
// media
import flash.media.*;
// net
import flash.net.URLLoader;
import flash.net.URLRequest;
// system
import flash.system.Security;
public class stanwidget extends MovieClip
{
// -- VARS
// xml
public var X:easyxml;
// wildfire
public var _wf:wildfire;
// stage dimentions
public var _sw:Number;
public var _sh:Number;
public var _swc:Number;
public var _shc:Number;
// player info
public var _count:uint; // total number of items
public var _now:uint; // current media item
public var _old:uint; // previous media item
// media info
public var _sound:Sound; // the sound item
private var _scn:SoundChannel; // the sound channel
// controller
public var _ctrl:ctrl_mc; // player controlls
// visualizer
public var _vis:audiovis; // audio visualizer
// link to site
public var _http:String = "http://widget.stanbush.com/mp3player/";
/*
--------------------------------------------------------
SET IT UP
--------------------------------------------------------
*/
public function stanwidget( )
{
//Set up security
Security.allowDomain("widget.stanbush.com");
Security.allowInsecureDomain("widget.stanbush.com");
_sw = stage.stageWidth;
_sh = stage.stageHeight;
_swc = _sw / 2;
_shc = _sh / 2;
//X = new easyxml( _http+'music.xml', this );
X = new easyxml( _http+'music.xml', this );
_wf = new wildfire( _http, '1109321', 'StanBush', 2, 2, _sw - 4, _sh - 4 );
this.loaderInfo.addEventListener (ProgressEvent.PROGRESS, preload);
init();
}
/*
--------------------------------------------------------
PRELOADER
--------------------------------------------------------
*/
private function preload( e:ProgressEvent) : void
{
var pcent:Number = e.bytesLoaded/e.bytesTotal*100;
//pre_bar.gotondtop( Math.floor( pcent/100 ) );
pre_txt.text = "LOADING " + int(pcent) + "%";
if(pcent==100)
{
/*
pre_bar.visible = false;
pre_bar.y = _sh + 1000;
init();
*/
pre_txt.visible = false;
pre_txt.y = _sh + 1000;
}
}
/*
--------------------------------------------------------
START CLASS
--------------------------------------------------------
*/
// INIT
public function init() : void
{
addChild( X );
// after xml loads start effects
this.addEventListener( 'XMLFIN', startup );
}
// START UP
private function startup( e:Event ) : void
{
/*
trace( '---------------');
trace( X._arr[0]._title );
trace( X._arr[0]._artist );
trace( X._arr[0]._album );
trace( X._arr[0]._shop );
trace( X._arr[0]._img );
trace( X._arr[0]._vid );
trace( X._arr[0]._link );
trace( '---------------');
*/
// add visualizer
_vis = new audiovis();
_vis.y = 0;
_vis.x = 0;
_vis.name = 'vis';
addChild( _vis );
_vis.init( this );
// add controller
_ctrl = new ctrl_mc();
_ctrl.name = 'ctrl_mc';
_ctrl.y = _sh;
_ctrl.x = _swc;
addChild( _ctrl );
_ctrl.init( this );
// put wildfire on top
addChild( _wf );
// detect mouse leave events
stage.addEventListener(Event.MOUSE_LEAVE, mouseLeft);
stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseBack);
}
/*
--------------------------------------------------------
DETECT MOUSE
--------------------------------------------------------
*/
private function mouseLeft( e:Event ) : void
{
_ctrl.aniOut();
}
private function mouseBack( e:Event ) : void
{
_ctrl.aniIn();
}
/*
PLAY MEDIA
*/
// -- END CLASS
}
// -- END PACKAGE
}