FlowPlayer
FlowPlayer coded by lx at www.lxidea.cn
version: alpha 1.3
/*
FlowPlayer coded by lx at www.lxidea.cn
version: alpha 1.3
*/
package {
import flash.display.Stage;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.errors.IOError;
import flash.geom.*;
import flash.display.Sprite;
import flash.utils.Timer;
import flash.ui.ContextMenu;
import flash.events.*;
import flash.text.*;
public class FlowPlayer extends Sprite {
private var mainframe:Sprite;
private var topframe:maintop;
private var _contextmenu:ContextMenu;
public function FlowPlayer() {
_contextmenu=new ContextMenu ;
_contextmenu.hideBuiltInItems();
contextMenu=_contextmenu;
stage.scaleMode=StageScaleMode.NO_SCALE;
stage.align=StageAlign.TOP_LEFT;
stage.frameRate=40;
mainframe=new Sprite ;
mainframe.width=stage.stageWidth;
mainframe.height=stage.stageHeight;
mainframe.x=0;
mainframe.y=0;
addChild(mainframe);
topframe=new maintop(this.stage.loaderInfo.url.toLowerCase().replace('flowplayer.swf','song.xml'));
topframe.x=0;
topframe.y=0;
addChild(topframe);
}
}
}
import flash.display.Sprite;
import flash.events.*;
import flash.events.EventDispatcher;
import flash.display.GradientType;
import flash.geom.Matrix;
import flash.text.TextField;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.xml.XMLDocument;
import flash.utils.setTimeout;
import flash.net.URLRequest;
import flash.display.Loader;
class maintop extends Sprite {
private var myframe:Sprite;
private var mybg:Bitmap;
private var mybgdata:BitmapData;
private var mytime:time;
private var playbutton:coolbutton;
private var stopbutton:coolbutton;
private var prebutton:coolbutton;
private var nextbutton:coolbutton;
private var _songmsg1:flowtext;
private var _songmsg2:flowtext;
internal var _playbar:dragbar;
private var _playlist:playlist;
internal var _core:core;
internal var _event:Event;
private var _EQ:EQ;
public function maintop(list:String='song.xml') {
myframe=new Sprite;
myframe.height=120;
myframe.width=280;
graphics.lineStyle(1,0x999999,1,true,'none','none',null,3);
graphics.beginFill(0xaabbcc,0.6);
graphics.drawRect(2,2,275,117);
graphics.endFill();
graphics.lineStyle(1,0x999999,0.4,true,'none','none',null,3);
graphics.moveTo(3,6);
graphics.curveTo(180,50,220,117);
graphics.moveTo(3,4);
graphics.curveTo(200,50,270,118);
_core=new core ;
addChild(_core);
addbutton(playbutton,5,85,25,30,'play');
addbutton(stopbutton,35,85,25,30,'stop');
addbutton(prebutton,65,85,25,30,'previous');
addbutton(nextbutton,95,85,25,30,'next');
addtime(mytime,10,6,'00:00',0,_core);
_songmsg1=new flowtext(125,'Times New Roman',14,'left',_core);
_songmsg1.x=150;
_songmsg1.y=8;
addChild(_songmsg1);
_core.addEventListener('songmsg1',_songmsg1.onchange);
_core.addEventListener('error',_songmsg1.onerror);
_songmsg1.changeContext('Flow Player is Ready Now');
_songmsg2=new flowtext(100,'Digital',12,'right',_core);
_songmsg2.x=175;
_songmsg2.y=32;
addChild(_songmsg2);
_songmsg2.changeContext('');
_core.addEventListener('songmsg2',_songmsg2.onchange);
_playbar=new dragbar(200,_core);
_playbar.x=2;
_playbar.y=36;
addChild(_playbar);
_playlist=new playlist(_core,list);
_playlist.y=120;
addChild(_playlist);
_EQ = new EQ(_core);
_EQ.x = 10;
_EQ.y = 25;
addChild(_EQ);
}
private function Fplay(e:Event) {
_core.playsound(_playlist.currentSong);
}
private function Fstop(e:Event) {
_core.stopsound();
}
private function Fprev(e:Event) {
_playlist.turnprev();
}
private function Fnext(e:Event) {
_playlist.turnnext();
}
private function addbutton(mybutton:coolbutton,X:int,Y:int,H:int,W:int,Name:String) {
mybutton=new coolbutton(H,W,Name);
mybutton.x=X;
mybutton.y=Y;
mybutton.addButtonEvent();
addChild(mybutton);
if (Name == 'play') {
mybutton.addEventListener(MouseEvent.CLICK,Fplay);
}
if (Name == 'stop') {
mybutton.addEventListener(MouseEvent.CLICK,Fstop);
}
if (Name == 'previous') {
mybutton.addEventListener(MouseEvent.CLICK,Fprev);
}
if (Name == 'next') {
mybutton.addEventListener(MouseEvent.CLICK,Fnext);
}
}
private function addtime(mytime:time,X:int,Y:int,times:String,color:uint,_core:core) {
mytime=new time(times,color,_core);
mytime.x=X;
mytime.y=Y;
addChild(mytime);
}
}
import flash.display.BitmapData;
import flash.display.Bitmap;
import flash.geom.ColorTransform;
import flash.geom.Point;
import flash.system.System;
//import org.cove.ape.*;
class EQ extends Sprite {
private var _corer:core;
private var _mode:int;
private var _canvas:Sprite;
private var bmp:BitmapData;
private var _bytes:ByteArray;
private var _bit:Array;
private var colors:Array;
private var alphas:Array;
private var ratios:Array;
private var _transMatrix:Matrix;
private var _mask:Sprite;
private var _changebutton:coolbutton;
private var _bmp:BitmapData;
private var bitmap:Bitmap;
private var rect:Rectangle;
private var matrix:Matrix;
private var colortrans:ColorTransform;
private var _filter:BlurFilter;
private var pt:Point;
private var oldy:int;
private var i:int,_x:int;
private var sc:int,b0:int,b1:int;
private var sum:Number,_y:Number;
private var color:uint;
private var container:Sprite;
public function EQ(_core:core) {
_mask = new Sprite();
_mask.graphics.beginFill(0);
for (var i=0;i<20;i++) {
_mask.graphics.drawRect(0,i*2+23,270,1);
}
addChild(_mask);
_mode = 1;
_corer = _core;
_canvas = new Sprite();
_canvas.mask = _mask;
addChild(_canvas);
_bytes = new ByteArray();
_bit = new Array();
_transMatrix = new Matrix();
_transMatrix.createGradientBox(270,60,Math.PI / 2,0,0);
matrix = new Matrix();
matrix.translate(2,0);
colortrans = new ColorTransform(1,1,1,1,1,1,1,0);
colors = new Array();
colors = [0xff0000,0xff6600,0x000a6c];
alphas = new Array();
alphas = [1,1,1];
ratios = new Array();
ratios = [0,127,250];
_changebutton = new coolbutton(20,12,'changemode');
_changebutton.x = 120;
_changebutton.y = 62;
addChild(_changebutton);
_changebutton.addButtonEvent();
_changebutton.addEventListener('changemode',changemode);
var EQtxt:TextField = new TextField();
EQtxt.x = 122;
EQtxt.y = 66;
EQtxt.defaultTextFormat = new TextFormat('Times New Roman',12,0x555555);
EQtxt.text = '↓';
EQtxt.mouseEnabled = false;
EQtxt.selectable = false;
EQtxt.height = 24;
EQtxt.width = 15;
addChild(EQtxt);
_bmp = new BitmapData(260,34,false,0xffffff);
bitmap = new Bitmap(_bmp);
bitmap.y = 25;
addChild(bitmap);
bitmap.visible = false;
rect = new Rectangle(0,0,2,12);
_filter = new BlurFilter(2,2,1);
pt = new Point(0,0);
addEQ();
oldy = 18;
container = new Sprite();
addChild(container);
}
private function addEQ() {
setInterval(showEQ,25);
}
public function changemode(e:Event) {
_mode = ++_mode-int(_mode/3)*3;
}
private function showEQ() {
switch(_mode) {
case 1:
if (container.visible) {
_canvas.visible = true;
_mask.visible = true;
bitmap.visible = false;
alpha = 1;
container.visible = false;
}
_bytes = _corer.provideSoundBytes(_bytes,true,2);
_bytes.position = 0;
for (var i=0; i<_bytes.length/4; i++) {
_bit[i]=_bytes.readFloat();
}
_canvas.graphics.clear();
_canvas.graphics.beginGradientFill('linear',colors,alphas,ratios,_transMatrix);
b0 = 0;
for (_x=0;_x<44;_x++) {
sum = 0;
b1 = Math.pow(2,_x*8/43);
if (b1>255) b1=255;
if (b1<=b0) b1=b0+1;
sc=8+b1-b0;
for (;b0<b1;b0++) sum+=(_bit[1+b0]+_bit[256+b0])/2;
_y = Math.sqrt(sum/Math.log(sc)/Math.LN10)*42;
if (_y>30) _y=30;
_canvas.graphics.drawRect(_x*6,59-_y,4,_y+1);
}
_canvas.graphics.endFill();
break;
case 2:
if (_mask.visible) {
_canvas.visible = false;
_mask.visible = false;
bitmap.visible = true;
alpha = 0.5;
container.visible = false;
}
_bytes = _corer.provideSoundBytes(_bytes,false,0);
_bytes.position = 0;
for (i=0; i<_bytes.length/4; i++) {
_bit[i]=_bytes.readFloat();
}
rect.y = 10;
rect.x = 5;
for (i=0; i<8;i++) {
rect.y += _bit[200+i]*2;
}
//rect.y = 18 + Math.sqrt(Math.log(rect.y));
color = (rect.y - 10)*(1<<16|1<<8|1<<2);
/*_bytes[64] << 16 | _bytes[128] << 8 | _bytes[256]*/
_bmp.fillRect(rect,color);
//_bmp.applyFilter(_bmp,_bmp.rect,pt,_filter);
_bmp.draw(_bmp,matrix,colortrans,null,null,false);
break;
case 0:
if (bitmap.visible) {
_canvas.visible = false;
_mask.visible = false;
bitmap.visible = false;
alpha = 1;
container.visible = true;
}
_bytes = _corer.provideSoundBytes(_bytes,true,0);
_bytes.position = 0;
break;
}
}
}
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.media.SoundMixer;
import flash.media.SoundLoaderContext;
import flash.media.SoundTransform;
import flash.media.ID3Info;
import flash.utils.setInterval;
import flash.utils.clearInterval;
import flash.utils.ByteArray;
class core extends Sprite {
private var _core:Sprite;
private var _id3:ID3Info;
private var _urlquest:URLRequest;
private var _url:String;
private var _isplaying:Boolean;
public var _oldpos:int;
public var _currentpos:int;
private var _uid:uint;
private var _channel:SoundChannel;
private var _transform:SoundTransform;
private var _loader:SoundLoaderContext;
private var _song:Sound=new Sound ;
private var _songmsg:String;
private var _begin:Boolean;
private var _volume:Sprite;
private var _volback:Sprite;
private var _vol:Number;
private var _volbar:coolbutton;
private var _draging:Boolean;
public function core() {
_songmsg=new String('');
_id3=new ID3Info ;
_song=new Sound ;
_song.addEventListener(IOErrorEvent.IO_ERROR,onerror);
_song.addEventListener(Event.ID3,readId3);
_song.addEventListener(ProgressEvent.PROGRESS,onprogress);
_loader=new SoundLoaderContext(10000,false);
_vol=1;
_transform=new SoundTransform(_vol,0);
_volume=new Sprite();
// _volume.graphics.beginFill(new uint(0x555555));
_volume.graphics.beginGradientFill(GradientType.LINEAR,[0x555555,0x6d5555],[1,1],[155,200],null,"pad");
_volume.graphics.moveTo(0,20);
_volume.graphics.lineTo(60,5);
_volume.graphics.lineTo(60,20);
_volume.graphics.lineTo(0,20);
_volume.graphics.endFill();
_volume.x = 150;
_volume.y = 88;
addChildAt(_volume,0);
_volbar=new coolbutton(20,10,'vol');
_volbar.x = 200;
_volbar.y = 87;
_draging=false;
_volbar.addButtonEvent();
_volbar.addEventListener(MouseEvent.MOUSE_DOWN, onDown);
_volbar.addEventListener(MouseEvent.MOUSE_UP, onUp);
_volbar.addEventListener(MouseEvent.MOUSE_MOVE, onMove);
addChildAt(_volbar,1);
_url=new String;
_urlquest=new URLRequest;
_oldpos=0;
_currentpos=0;
setInterval(compare,200);
}
private function onMove(e:MouseEvent) {
if (_draging) {
_transform.volume=(_volbar.x-150)/50;
}
}
private function onDown(e:MouseEvent) {
this.stage.addEventListener(MouseEvent.MOUSE_UP, onUp);
_volbar.startDrag(false,new Rectangle(150,88,50,0));
_draging=true;
}
private function onUp(e:MouseEvent) {
_volbar.stopDrag();
this.stage.removeEventListener(MouseEvent.MOUSE_UP, onUp);
_draging=false;
}
public function soundaccess():Boolean {
return ! SoundMixer.areSoundsInaccessible();
}
public function provideSoundBytes(_bytes:ByteArray,FFT:Boolean,factor:int):ByteArray {
if (factor > 2) {
factor=2;
}
if (factor < 0) {
factor=0;
}
try {
SoundMixer.computeSpectrum(_bytes,FFT,factor);
_bytes[1024]=1;
} catch (e) {
_bytes[1024]=0;
}
return _bytes;
}
private function addTimerPeek() {
_uid=setInterval(Peeker,200);
}
private function removeTimerPeek() {
clearInterval(_uid);
}
private function Peeker() {
if (_channel) {
_currentpos=_channel.position;
_channel.soundTransform=_transform;
}
}
private function onprogress(e:Event) {
dispatchEvent(new Event('songmsg2',false,true));
}
private function compare() {
if (_currentpos == _oldpos || ! _channel) {
_isplaying=false;
} else {
_isplaying=true;
_oldpos=(_channel)?_currentpos:0;
}
}
public function get isplaying():Boolean {
return _isplaying;
}
public function get hasContext():Boolean {
if (_song.length > 0) {
return true;
} else {
return false;
}
}
private function oncomplete(e:Event) {
if (_song.bytesLoaded==_song.bytesTotal) {
reset();
next();
}
}
private function onerror(e:IOErrorEvent) {
dispatchEvent(new Event('error',false,true));
setTimeout(next,2000);
}
private function next() {
dispatchEvent(new Event('next',false,true));
}
public function loadsound(url:String,msg:String) {
if (_url==url) {
return;
}
_songmsg=msg;
dispatchEvent(new Event('songmsg1',false,true));
if (_url != url) {
if (_channel) {
_channel.stop();
_channel.removeEventListener(Event.SOUND_COMPLETE,oncomplete);
_channel = null;
removeTimerPeek();
}
_song.removeEventListener(IOErrorEvent.IO_ERROR,onerror);
_song.removeEventListener(Event.ID3,readId3);
_song.removeEventListener(ProgressEvent.PROGRESS,onprogress);
_song = null;
_song = new Sound() ;
_song.addEventListener(Event.ID3,readId3);
_song.addEventListener(ProgressEvent.PROGRESS,onprogress);
_url=url;
_urlquest.url = _url;
_song.addEventListener(IOErrorEvent.IO_ERROR,onerror);
_song.load(_urlquest,_loader);
reset();
_oldpos=0;
_currentpos=0;
} else {
if (! hasContext) {
_url=url;
_urlquest=new URLRequest(_url);
_song.load(_urlquest,_loader);
_oldpos=0;
_currentpos=0;
}
}
justplay();
addTimerPeek();
}
public function stopsound() {
if (_song.url != null) {
_currentpos=0;
_oldpos=0;
reset();
_oldpos=0;
_currentpos=0;
if (_channel) {
_channel.stop();
_channel = null;
removeTimerPeek();
}
}
}
public function playsound(url:String) {
if (url == 'null') {
return;
}
if (_url == url) {
if (_currentpos == _song.length) {
_currentpos=0;
}
if (isplaying) {
_channel.stop();
removeTimerPeek();
_channel.removeEventListener(Event.SOUND_COMPLETE,oncomplete);
_channel = null;
} else {
if (_channel) {
_channel.stop();
removeTimerPeek();
_channel.removeEventListener(Event.SOUND_COMPLETE,oncomplete);
_channel = null;
}
justplay();
addTimerPeek();
}
} else {
_channel.stop();
_channel = null;
_currentpos=0;
loadsound(url,'');
justplay();
addTimerPeek();
}
}
private function justplay() {
_channel=_song.play(_currentpos,0,_transform);
_channel.addEventListener(Event.SOUND_COMPLETE,oncomplete);
}
public function reset() {
dispatchEvent(new Event('reset',false,true));
}
public function playfrompos(pos:int) {
if (_song.bytesLoaded > 0) {
if (isplaying) {
if (_channel) {
_channel.stop();
_channel.removeEventListener(Event.SOUND_COMPLETE,oncomplete);
}
_channel=_song.play(pos,0,_transform);
_channel.addEventListener(Event.SOUND_COMPLETE,oncomplete);
} else {
_currentpos=pos;
_oldpos=pos;
}
}
}
public function get posStr():String {
if (_channel) {
return Convert.time2String(position / 1000);
}
return '00:00';
}
public function get position():int {
return _currentpos;
}
public function get availLength():Number {
if (_song.bytesTotal>0) {
return _song.bytesLoaded / (_song.bytesTotal);
}
return 0;
}
public function get length():int {
return _song.length;
}
private function readId3(e:Event) {
_id3=e.currentTarget.id3;
_songmsg=EncodeUtf8(_id3.artist + '-' + _id3.songName);
dispatchEvent(new Event('songmsg1',false,true));
}
public function get songmsg1():String {
return _songmsg;
}
public function get songmsg2():String {
if (_song.bytesLoaded > 0) {
var bps:int = _song.bytesLoaded / _song.length;
var vbps:int = Math.round(bps/8)*8;
var pbps:int = bps-vbps;
var str:String;
if (pbps>0) {
str = 'A '+ bps*8 +'Kbps';
} else if(pbps<0) {
str = 'V '+ bps*8 +'Kbps';
} else {
str = 'C ' + bps*8 +'Kbps';
}
return str;
}
return '';
}
function EncodeUtf8(str:String):String {
if (str != null) {
var oriByteArr:ByteArray=new ByteArray ;
oriByteArr.writeUTFBytes(str);
var needEncode:Boolean=false;
for (var i=0; i < oriByteArr.length; i+= 2) {
if (oriByteArr[i] == 195 || oriByteArr[i] == 194) {
needEncode=true;
break;
}
if (oriByteArr[i] == 32) {
i--;
}
}
if (needEncode) {
var tempByteArr:ByteArray=new ByteArray ;
for (i=0; i < oriByteArr.length; i++) {
if (oriByteArr[i] == 194) {
tempByteArr.writeByte(oriByteArr[i + 1]);
i++;
} else if (oriByteArr[i] == 195) {
tempByteArr.writeByte(oriByteArr[i + 1] + 64);
i++;
} else {
tempByteArr.writeByte(oriByteArr[i]);
}
}
tempByteArr.position=0;
return tempByteArr.readMultiByte(tempByteArr.bytesAvailable,"chinese");
} else {
return str;
}
} else {
return "";
}
delete i;
}
}
class dragbar extends Sprite {
private var _bufferbar:Sprite;
private var _dragbar:coolbutton;
private var _uid:uint;
private var _Tlength:int;
private var _coreReferer:core;
private var _maxX:int;
private var _buttondown:Boolean;
public function dragbar(Tlength:int,_core:core) {
_buttondown=false;
_coreReferer=_core;
_Tlength=Tlength;
_dragbar=new coolbutton(10,16,'bar');
_dragbar.addButtonEvent();
_dragbar.addEventListener(MouseEvent.MOUSE_DOWN,onpress);
_dragbar.addEventListener(MouseEvent.MOUSE_UP,onrelease);
_dragbar.addEventListener(MouseEvent.MOUSE_OVER,onhover);
_core.addEventListener('reset',reset);
addChild(_dragbar);
set2update(_core);
}
private function set2update(_coreReferer:core) {
_uid=setInterval(updatepos,200,_coreReferer);
}
private function reset(e:Event) {
var tmpx:int= 0;//_coreReferer.position * _Tlength * _coreReferer.availLength / _coreReferer.length;
graphics.clear();
graphics.lineStyle(1,0,0.4,true,'none','none',null,3);
graphics.beginFill(0,0);
graphics.drawRect(3,5,_Tlength + 1,5);
graphics.endFill();
graphics.lineStyle(1,0,0,true,'none','none',null,3);
graphics.beginFill(0x99aabb,0.9);
try {
graphics.drawRect(4,6,_Tlength * _coreReferer.availLength,4);
} catch(e) {
}
graphics.endFill();
graphics.beginFill(0x112233,0.7);
graphics.drawRect(4,6,_dragbar.x,4);
graphics.endFill();
try {
graphics.drawRect(4,6,tmpx,4);
_dragbar.x=int(tmpx);
}
catch (e) {
}
}
private function updatepos(_coreReferer:core) {
var tmpx:Number =_coreReferer.position * _Tlength * _coreReferer.availLength / _coreReferer.length;
graphics.clear();
graphics.lineStyle(1,0,0.4,true,'none','none',null,3);
graphics.beginFill(0,0);
graphics.drawRect(3,5,_Tlength + 1,5);
graphics.endFill();
graphics.lineStyle(1,0,0,true,'none','none',null,3);
graphics.beginFill(0x99aabb,0.9);
try {
graphics.drawRect(4,6,_Tlength * _coreReferer.availLength,4);
} catch (e) {
}
graphics.endFill();
graphics.beginFill(0x112233,0.7);
graphics.drawRect(4,6,_dragbar.x,4);
graphics.endFill();
if (_buttondown || ! _coreReferer.isplaying) {
return;
}
try {
graphics.drawRect(4,6,tmpx,4);
_dragbar.x=int(tmpx);
} catch (e) {
}
}
private function onhover(e:MouseEvent) {
_buttondown=e.buttonDown;
}
private function onpress(e:MouseEvent) {
startdrag();
_buttondown=e.buttonDown;
this.stage.addEventListener(MouseEvent.MOUSE_UP,onrelease);
}
public function mouseup(e:MouseEvent) {
_buttondown=e.buttonDown;
}
public function onrelease(e:MouseEvent) {
this.stage.removeEventListener(MouseEvent.MOUSE_UP,onrelease);
_dragbar.stopDrag();
_coreReferer.playfrompos(_dragbar.x * _coreReferer.length / _maxX);
_buttondown=e.buttonDown;
}
private function startdrag() {
_maxX=_coreReferer.availLength * _Tlength;
_dragbar.startDrag(false,new Rectangle(0,0,_maxX,0));
}
}
import flash.utils.setTimeout;
import flash.utils.clearTimeout;
import flash.filters.*;
class flowtext extends Sprite {
private var _mytext:TextField;
private var _mymask:Sprite;
private var _movement:int;
private var _uid:uint;
private var _maxwidth:int;
private var _corer:core;
private var _align:String;
private var _X:int;
private var _Y:int;
public function flowtext(width:int,font:String,fontsize:int,align:String,_core:core) {
_corer=_core;
_align=align;
_maxwidth=width;
_movement=0;
_mymask=new Sprite ;
with (_mymask.graphics) {
beginFill(0);
drawRect(0,0,width,24);
endFill();
}
addChild(_mymask);
mask=_mymask;
_mytext=new TextField ;
_mytext.defaultTextFormat=new TextFormat(font,fontsize,0,false,false,false,'');
_mytext.selectable=false;
_mytext.mouseEnabled=false;
_mytext.height=24;
_mytext.autoSize=align;
_mytext.sharpness = -200;
addChild(_mytext);
_mytext.text='';
}
public function changeContext(str:String) {
clearTimeout(_uid);
_mytext.x-= _movement;
_movement=0;
_mytext.text=str;
if (_align == 'left') {
textmoveleft();
}
if (_align == 'right') {
textmoveright();
}
}
public function onerror(e:Event) {
changeContext('打开文件时出错!');
}
public function onchange(e:Event) {
if (e.type == 'songmsg1') {
changeContext(_corer.songmsg1);
}
if (e.type == 'songmsg2') {
changeContext(_corer.songmsg2);
}
}
private function textmoveleft() {
if (_mytext.width < _maxwidth + 3) {
_mytext.x-= _movement;
clearTimeout(_uid);
_movement=_maxwidth - _mytext.width;
_mytext.x+= _movement;
return;
}
_mytext.x--;
_movement--;
if (_mytext.width + _movement <= _maxwidth) {
_uid=setTimeout(textmoveright,1500);
} else {
_uid=setTimeout(textmoveleft,100);
}
}
private function textmoveright() {
if (_mytext.width < _maxwidth) {
_mytext.x-= _movement;
clearTimeout(_uid);
return;
}
_mytext.x++;
_movement++;
if (_movement >= 0) {
_uid=setTimeout(textmoveleft,1500);
} else {
_uid=setTimeout(textmoveright,100);
}
}
}
class time extends Sprite {
private var _time:Sprite;
private var _color:uint;
private var _corer:core;
private var _uid:uint;
var _array:Array=[[2,4],[0,2,3,5,6],[0,2,4,5,6],[1,2,4,6],[0,1,4,5,6],[0,1,3,4,5,6],[0,2,4],[0,1,2,3,4,5,6],[0,1,2,4,5,6],[0,1,2,3,4,5],[7,8]];
public function time(txt:String,color:uint,_core:core) {
_corer=_core;
_color=color;
drawcall(txt,_color);
setInterval(redraw,50);
}
private function redraw() {
drawcall(Convert.time2String(_corer._oldpos/1000),_color);
}
public function draw(txt:String) {
drawcall(txt,_color);
}
private function drawcall(txt:String,color:uint) {
graphics.clear();
for (var i=0; i < txt.length; i++) {
if (txt.charAt(i) == ':') {
drawstring(i,':',color);
} else {
drawstring(i,txt.charAt(i),color);
}
}
}
private function drawstring(offset:int,str:String,color:uint) {
var i=int(str);
if (str == ':') {
i=11;
}
if (str == '0') {
i=10;
}
for (var j=0; j < _array[i - 1].length; j++) {
drawline(offset,_array[i - 1][j],color);
}
}
private function drawline(offset:int,num:int,color:uint) {
offset*= 20;
graphics.lineStyle(1,color,1,true,'none','none',null,3);
switch (num) {
case 0 :
with (graphics) {
moveTo(1 + offset,1);
lineTo(15 + offset,1);
moveTo(2 + offset,2);
lineTo(14 + offset,2);
moveTo(3 + offset,3);
lineTo(13 + offset,3);
}
break;
case 1 :
with (graphics) {
moveTo(offset,3);
lineTo(offset,13);
moveTo(1 + offset,4);
lineTo(1 + offset,12);
moveTo(2 + offset,5);
lineTo(2 + offset,11);
}
break;
case 2 :
with (graphics) {
moveTo(16 + offset,3);
lineTo(16 + offset,13);
moveTo(15 + offset,4);
lineTo(15 + offset,12);
moveTo(14 + offset,5);
lineTo(14 + offset,11);
}
break;
case 3 :
with (graphics) {
moveTo(offset,15);
lineTo(offset,25);
moveTo(1 + offset,16);
lineTo(1 + offset,24);
moveTo(2 + offset,17);
lineTo(2 + offset,23);
}
break;
case 4 :
with (graphics) {
moveTo(16 + offset,15);
lineTo(16 + offset,25);
moveTo(15 + offset,16);
lineTo(15 + offset,24);
moveTo(14 + offset,17);
lineTo(14 + offset,23);
}
break;
case 5 :
with (graphics) {
moveTo(1 + offset,27);
lineTo(15 + offset,27);
moveTo(2 + offset,26);
lineTo(14 + offset,26);
moveTo(3 + offset,25);
lineTo(13 + offset,25);
}
break;
case 6 :
with (graphics) {
moveTo(3 + offset,13);
lineTo(13 + offset,13);
moveTo(2 + offset,14);
lineTo(14 + offset,14);
moveTo(3 + offset,15);
lineTo(13 + offset,15);
}
break;
case 7 :
with (graphics) {
drawRect(6 + offset,6,3,3);
drawRect(6 + offset,6,2,2);
drawRect(6 + offset,6,1,1);
}
break;
case 8 :
with (graphics) {
drawRect(6 + offset,18,3,3);
drawRect(6 + offset,18,2,2);
drawRect(6 + offset,18,1,1);
}
break;
}
}
}
class playlist extends Sprite {
internal var _songlist:songlist;
private var _list:Array;
private var _listUI:listUI;
private var _scrollbar:scrollbar;
private var _corer:core;
private var _onoff:coolbutton;
private var _PL_text:TextField;
public function playlist(_core:core,address:String="song.xml") {
super();
_corer=_core;
graphics.lineStyle(1,0x999999,1,true,'none','none',null,3);
graphics.beginFill(0xaabbcc,0.6);
graphics.drawRect(2,2,275,235);
graphics.endFill();
graphics.lineStyle(1,0x999999,0.4,true,'none','none',null,3);
graphics.moveTo(272,2);
graphics.curveTo(277,4,274,16);
graphics.curveTo(260,140,2,220);
graphics.moveTo(222,2);
graphics.curveTo(250,80,110,237);
_songlist=new songlist(address);
_songlist.addEventListener('readxml',readxml2list);
_corer.addEventListener('next',turn2next);
_corer.addEventListener('previous',turn2prev);
addChild(_songlist);
_onoff=new coolbutton(20,32,'PL');
_onoff.x = 238;
_onoff.y = -32;
_onoff.addButtonEvent();
addChild(_onoff);
_PL_text=new TextField;
_PL_text.mouseEnabled = false;
_PL_text.selectable = false;
_PL_text.text = 'PL';
_PL_text.x = 249;
_PL_text.y = -29;
addChild(_PL_text);
addEventListener('PL',onoff);
}
private function onoff(e:Event) {
_listUI.visible = !(_listUI.visible);
_scrollbar.visible = _listUI.visible;
if (_listUI.visible) {
graphics.lineStyle(1,0x999999,1,true,'none','none',null,3);
graphics.beginFill(0xaabbcc,0.6);
graphics.drawRect(2,2,275,235);
graphics.endFill();
graphics.lineStyle(1,0x999999,0.4,true,'none','none',null,3);
graphics.moveTo(272,2);
graphics.curveTo(277,4,274,16);
graphics.curveTo(260,140,2,220);
graphics.moveTo(222,2);
graphics.curveTo(250,80,110,237);
} else {
graphics.clear();
}
}
internal function readxml2list(e:Event) {
_list=new Array ;
for (var i=0; i < _songlist._xml.child('song').length(); i++) {
var _song:Array=new Array ;
_song.push(_songlist._xml.child('song')[i].attribute('name'));
_song.push(_songlist._xml.child('song')[i].attribute('artist'));
_song.push(_songlist._xml.child('song')[i].attribute('address'));
_list.push(_song);
}
_listUI=new listUI(_list);
addChild(_listUI);
_scrollbar=new scrollbar(_list.length * 25,235);
_scrollbar.x=253;
_scrollbar.y=1;
addChild(_scrollbar);
addEventListener(MouseEvent.MOUSE_WHEEL,_scrollbar.wheelmove);
_scrollbar.addEventListener('move',_listUI.movelistener);
_listUI.addEventListener('focus',focuslistener);
}
public function turnnext() {
if (_list.length>0 && _listUI.focus<_list.length) {
_listUI.focusplus();
}
}
public function turnprev() {
if (_list.length>0 && _listUI.focus>1) {
_listUI.focusminus();
}
if (_list.length>0 && _listUI.focus==-1) {
_listUI.focusminus();
}
}
public function turn2next(e:Event) {
turnnext();
}
public function turn2prev(e:Event) {
turnprev();
}
private function focuslistener(e:Event) {
_corer.loadsound(_list[_listUI.focus - 1][2],_list[_listUI.focus - 1][1] + '-' + _list[_listUI.focus - 1][0]);
_corer.reset();
}
public function get currentSong():String {
if (_listUI.focus > 0) {
return _list[_listUI.focus - 1][2];
}
return 'null';
}
}
class scrollbar extends Sprite {
private var _upbar:coolbutton;
private var _downbar:coolbutton;
internal var bar:coolbutton;
internal var avail:int;
internal var Total:int;
public function scrollbar(available:int,total:int) {
avail=available;
Total=total + 10;
_upbar=new coolbutton(20,20,'up');
_downbar=new coolbutton(20,20,'down');
addChild(_upbar);
_downbar.y=212;
addChild(_downbar);
var factor:Number=available / total;
if (factor < 1) {
factor=1;
}
bar=new coolbutton(int(191 / factor),20,'move');
bar.y=21;
bar.addButtonEvent();
addChild(bar);
}
public function wheelmove(e:MouseEvent) {
if (bar.y > 21 && e.delta > 0) {
bar.y-= e.delta * 4;
if (bar.y < 21) {
bar.y=21;
}
}
if (bar.y < 212 - bar.height && e.delta < 0) {
bar.y-= e.delta * 4;
if (bar.y > 212 - bar.height) {
bar.y=212 - bar.height;
}
}
bar.dispatchEvent(bar._event);
}
}
class listUI extends Sprite {
internal var _event:Event;
internal var _linebutton:linebutton;
private var _mask:Sprite;
internal var _buttonarray:Array;
private var _focus:int;
public function listUI(_list:Array) {
_focus=-1;
_mask=new Sprite ;
_buttonarray=new Array ;
_mask.x=0;
_mask.y=0;
addChild(_mask);
with (_mask) {
graphics.beginFill(0,1);
graphics.drawRect(3,3,272,233);
graphics.endFill();
}
mask=_mask;
for (var i=0; i < _list.length; i++) {
var str:String=_list[i][1] + ' - ' + _list[i][0];
if (str.length<=3) {
str = '未命名曲目';
}
_linebutton=new linebutton(i + 1,str);
_linebutton.x=1;
_linebutton.y=1 + i * 25;
addChild(_linebutton);
_buttonarray.push(_linebutton);
_linebutton.addEventListener(String(i + 1),drawframe);
addEventListener('redrawframe',drawframe);
}
}
public function get focus():int {
if (_focus > 0) {
return _focus;
}
return -1;
}
public function focusplus() {
_focus ++;
if (_focus==0) {
_focus = 1;
}
dispatchEvent(new Event('redrawframe',false,true));
dispatchEvent(new Event('focus',false,true));
}
public function focusminus() {
_focus --;
if (_focus==-2) {
_focus = _buttonarray.length;
}
dispatchEvent(new Event('redrawframe',false,true));
dispatchEvent(new Event('focus',false,true));
}
public function movelistener(e:Event) {
with (e.currentTarget) {
var offset:int=(avail - Total + 13) * (bar.y - 21) / (191 - bar.height);
if (avail > Total) {
for (var i=0; i < _buttonarray.length; i++) {
_buttonarray[i].y=1 + i * 25 - offset;
}
}
}
dispatchEvent(new Event('redrawframe',false,true));
}
public function drawframe(e:Event) {
if (int(e.type) > 0) {
_focus=int(e.type);
}
if (_focus > 0) {
graphics.clear();
graphics.lineStyle(1,0x5198BE,1,true,'none','none',null,3);
graphics.drawRoundRect(_buttonarray[_focus - 1].x + 2,_buttonarray[_focus - 1].y + 2,251,25,2,2);
graphics.endFill();
}
if (e.currentTarget.toString() == '[object linebutton]') {
dispatchEvent(new Event('focus',false,true));
}
}
}
import flash.errors.IOError;
class songlist extends Sprite {
public var _songlist:Sprite;
internal var _xml:XML;
private var _xmlurl:URLRequest;
private var _xmlloader:URLLoader;
internal var _waiting:TextField;
internal var _event:Event;
public function songlist(url:String='song.xml') {
_event=new Event('readxml',false,true);
_songlist=new Sprite ;
_xml=new XML ;
_xmlurl=new URLRequest(url);
_xmlloader=new URLLoader ;
_xmlloader.load(_xmlurl);
_waiting=new TextField ;
_waiting.selectable=false;
_waiting.autoSize='center';
_waiting.height=20;
_waiting.text='读取歌曲列表..';
_waiting.x=96;
_waiting.y=20;
addChild(_waiting);
_xmlloader.addEventListener(Event.COMPLETE,loaded);
_xmlloader.addEventListener(IOErrorEvent.IO_ERROR,error);
}
private function loaded(e:Event) {
_waiting.visible=false;
try {
_xml=XML(_xmlloader.data);
dispatchEvent(_event);
} catch (e:TypeError) {
_waiting.multiline=true;
_waiting.text=e.message+'点击重试';
_waiting.visible=true;
addEventListener(MouseEvent.CLICK,function(){_xmlloader.load(_xmlurl);_waiting.text='重试读取中...'});
}
}
private function error(e:Event) {
_waiting.text='读取列表失败,请检查文件';
}
}
import flash.geom.Rectangle;
class coolbutton extends Sprite {
public var mybutton:Sprite;
private var colormatrix:Matrix;
private var colors:Array;
private var colorarray:Array;
public var myname:String;
internal var _event:Event;
internal var position:int;
public function coolbutton(height:Number=32,width:Number=64,name:String='null') {
_event=new Event(name,true,true);
myname=new String(name);
mybutton=new Sprite ;
colors=new Array ;
colors=[0xF5F5F5,0xE0E0E0,0xCFCFCF,0xB0B0B0];
colorarray=new Array ;
colorarray=[0,138,138,255];
colormatrix=new Matrix ;
colormatrix.createGradientBox(width,height,Math.PI / 2,0,0);
mybutton.height=height;
mybutton.width=width;
graphics.lineStyle(1,0x707070,1,true,'none','none',null,3);
graphics.drawRoundRect(3,3,width - 1,height - 1,3,3);
graphics.lineStyle(1,0xF3F3F3,1,true,'none','none',null,3);
graphics.beginGradientFill(GradientType.LINEAR,colors,[1,1,1,1],colorarray,colormatrix);
graphics.drawRoundRect(4,4,width - 3,height - 3,3,3);
graphics.endFill();
redraw(myname);
}
public function addButtonEvent() {
var mybutton=this;
mybutton.buttonMode=true;
mybutton.addEventListener(MouseEvent.MOUSE_MOVE,mybutton.onDrag);
mybutton.addEventListener(MouseEvent.CLICK,mybutton.onClick);
mybutton.addEventListener(MouseEvent.ROLL_OVER,mybutton.onhover);
mybutton.addEventListener(MouseEvent.ROLL_OUT,mybutton.onout);
mybutton.addEventListener(MouseEvent.MOUSE_DOWN,mybutton.onpress);
mybutton.addEventListener(MouseEvent.MOUSE_UP,mybutton.onrelease);
}
public function onhover(event:MouseEvent) {
var height=event.target.height;
var width=event.target.width;
if (event.buttonDown) {
graphics.lineStyle(1,0x2C628B,1,true,'none','none',null,3);
graphics.drawRoundRect(3,3,width - 1,height - 1,1,1);
graphics.lineStyle(1,0x63ACD3,1,true,'none','none',null,3);
graphics.beginGradientFill(GradientType.LINEAR,[0xE5F4FC, 0xC4E5F6, 0x98D1EF, 0x6DB6DD],[1,1,1,1],colorarray,colormatrix);
graphics.drawRoundRect(4,4,width - 3,height - 3,1,1);
graphics.endFill();
} else {
graphics.lineStyle(1,0x3C7FBE,1,true,'none','none',null,3);
graphics.drawRoundRect(3,3,width - 1,height - 1,1,1);
graphics.lineStyle(1,0xEFF9FE,1,true,'none','none',null,3);
graphics.beginGradientFill(GradientType.LINEAR,[0xF5F5F5, 0xD9F0FC, 0xBEE6FD, 0xA7D9F5],[1,1,1,1],colorarray,colormatrix);
graphics.drawRoundRect(4,4,width - 3,height - 3,1,1);
graphics.endFill();
}
redraw(myname);
}
public function onout(event:MouseEvent) {
var height=event.target.height;
var width=event.target.width;
graphics.lineStyle(1,0x707070,1,true,'none','none',null,3);
graphics.drawRoundRect(3,3,width - 1,height - 1,3,3);
graphics.lineStyle(1,0xF3F3FF,1,true,'none','none',null,3);
graphics.beginGradientFill(GradientType.LINEAR,colors,[1,1,1,1],colorarray,colormatrix);
graphics.drawRoundRect(4,4,width - 3,height - 3,3,3);
graphics.endFill();
redraw(myname);
}
public function onpress(event:MouseEvent) {
var height=event.target.height;
var width=event.target.width;
graphics.lineStyle(1,0x2C628B,1,true,'none','none',null,3);
graphics.drawRoundRect(3,3,width - 1,height - 1,3,3);
graphics.lineStyle(1,0x63ACD3,1,true,'none','none',null,3);
graphics.beginGradientFill(GradientType.LINEAR,[0xE5F4FC, 0xC4E5F6, 0x98D1EF, 0x6DB6DD],[1,1,1,1],colorarray,colormatrix);
graphics.drawRoundRect(4,4,width - 3,height - 3,3,3);
graphics.endFill();
redraw(myname);
}
public function onDrag(event:MouseEvent) {
if (myname == 'move') {
if (event.buttonDown) {
dispatchEvent(_event);
startdrag();
} else {
stopDrag();
}
}
}
public function startdrag() {
startDrag(false,new Rectangle(0,21,0,191 - height));
}
public function onrelease(event:MouseEvent) {
var height=event.target.height;
var width=event.target.width;
graphics.lineStyle(1,0x707070,1,true,'none','none',null,3);
graphics.drawRoundRect(3,3,width - 1,height - 1,3,3);
graphics.lineStyle(1,0xF3F3F3,1,true,'none','none',null,3);
graphics.beginGradientFill(GradientType.LINEAR,colors,[1,1,1,1],colorarray,colormatrix);
graphics.drawRoundRect(4,4,width - 3,height - 3,3,3);
graphics.endFill();
if (myname == 'move') {
stopDrag();
}
redraw(myname);
}
public function onClick(event:MouseEvent) {
dispatchEvent(_event);
}
private function redraw(iname:String) {
if (iname == 'play') {
/*
graphics.lineStyle(1,0x555555,1,true,'normal','none',null,3);
for (var i=10; i > 2; i--) {
graphics.moveTo(18 - i,17 - i);
graphics.lineTo(18 - i,12 + i);
}
graphics.lineStyle(3,0x555555,1,true,'normal','none',null,3);
graphics.moveTo(19,7);
graphics.lineTo(19,22);
graphics.moveTo(25,7);
graphics.lineTo(25,22);
*/
graphics.lineStyle(1,0,0);
graphics.beginFill(0x555555);
graphics.moveTo(8,7);
graphics.lineTo(18,15);
graphics.lineTo(8,23);
graphics.lineTo(8,7);
graphics.drawRect(19,7,3,16);
graphics.drawRect(25,7,3,16);
graphics.endFill();
}
if (iname == 'stop') {
graphics.lineStyle(0,0,0);
graphics.beginFill(0x555555,1);
graphics.drawRect(11,8.5,14,14);
graphics.endFill();
}
if (iname == 'previous') {
graphics.lineStyle(1,0,0);
graphics.beginFill(0x555555);
graphics.moveTo(17,7);
graphics.lineTo(7,15);
graphics.lineTo(17,23);
graphics.lineTo(17,7);
graphics.moveTo(28,7);
graphics.lineTo(18,15);
graphics.lineTo(28,23);
graphics.lineTo(28,7);
graphics.endFill();
}
if (iname == 'next') {
graphics.lineStyle(1,0,0);
graphics.beginFill(0x555555);
graphics.moveTo(8,7);
graphics.lineTo(18,15);
graphics.lineTo(8,23);
graphics.lineTo(8,7);
graphics.moveTo(19,7);
graphics.lineTo(29,15);
graphics.lineTo(19,23);
graphics.lineTo(19,7);
graphics.endFill();
}
}
}
import flash.filters.GlowFilter;
import flash.text.TextFormat;
import flash.text.TextFormatAlign;
class linebutton extends Sprite {
internal var _mybutton:coolbutton;
private var _idtext:TextField;
private var _infotext:TextField;
private var _flowfilter:GlowFilter;
public var _PressedId:Event;
public function linebutton(id:int,info:String) {
_PressedId=new Event(String(id),false,true);
_mybutton=new coolbutton(24,250,String(id));
_flowfilter=new GlowFilter(0xaaaaaa,1,2,2,2,1,false,false);
addChild(_mybutton);
_idtext=new TextField ;
_infotext=new TextField ;
_idtext.height=20;
_idtext.width=20;
_idtext.defaultTextFormat=new TextFormat('Times New Roman',12,0,false,false,false,'','','right');
_idtext.text=String(id);
_idtext.x=8;
_idtext.y=5;
_idtext.mouseEnabled=false;
_idtext.multiline=false;
_idtext.selectable=false;
_idtext.cacheAsBitmap=true;
_idtext.filters=[_flowfilter];
addChild(_idtext);
_infotext.height=20;
_infotext.width=200;
_infotext.defaultTextFormat=new TextFormat('Times New Roman',12,0,false,false,false,'','','justify');
_infotext.text=info;
_infotext.x=50;
_infotext.y=5;
_infotext.mouseEnabled=false;
_infotext.multiline=false;
_infotext.selectable=false;
_infotext.filters=[_flowfilter];
addChild(_infotext);
_mybutton.addButtonEvent();
}
}
class Convert {
public static function time2String(time:int):String {
var str:String='';
var str1:int=time / 60;
if (str1 < 10) {
str='0' + str1;
} else {
str=String(str1);
}
str+= ':';
var str2:int=time - str1 * 60;
if (str2 < 10) {
str+= '0' + str2;
} else {
str+= String(str2);
}
return str;
}
}