当前位置: 代码迷 >> Web前端 >> 简略的mp3播放器
  详细解决方案

简略的mp3播放器

热度:273   发布时间:2012-10-24 14:15:58.0
简单的mp3播放器
很简单的播放器,不过可以作为一种思路哦.
import flash.media.Sound;
import flash.events.Event;
import flash.media.SoundChannel;
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.net.URLRequest;

var sound:Sound = new Sound();
	sound.load(new URLRequest("d:/Temp/b.mp3"));
var sc:SoundChannel = sound.play();

addEventListener(Event.ENTER_FRAME,loop);

function loop(e:Event):void{
	
	track.scaleX = sc.position/sound.length;
}
//track
var w:int = 550;
var h:int = 400;
var track_y:int = h - 20;
var track:Sprite = new Sprite();
	addChild(track);
	track.y = track_y;
	track.graphics.beginFill(0xff0000);
	track.graphics.drawRoundRect(0,0,w,h,4,4);
	track.graphics.endFill();
	track.scaleX = 0;
	track.mouseChildren = false;

//progress
var progress:Sprite = new Sprite();
	addChild(progress);
	progress.y = track_y;
	progress.graphics.beginFill(0xCCCCCC,.4);
	progress.graphics.drawRoundRect(0,0,w,h,4,4);
	progress.graphics.endFill();
	progress.addEventListener(MouseEvent.CLICK,onClick);

function onClick(e:MouseEvent):void{
	sc.stop();
	sc = sound.play( (progress.mouseX/w) * sound.length);
}
  相关解决方案