600字范文,内容丰富有趣,生活中的好帮手!
600字范文 > 制作一个简单的音乐播放器

制作一个简单的音乐播放器

时间:2021-05-18 15:44:08

相关推荐

制作一个简单的音乐播放器

舞台布置及所加的元件如下图

然后直接在放代码即可. //声明

var jzdz:URLRequest=new URLRequest("http://59.52.188.151/s2.mp3");

var sywj:Sound=new Sound;

var sykz:SoundChannel=new SoundChannel;

var liu:SoundLoaderContext=new SoundLoaderContext(100000,true);

var ztwz:Number;

//初始化

hk_mc.buttonMode=true;

jd_mc.visible=false;

sywj.load(jzdz,liu);

sykz=sywj.play();

//加载过程

sywj.addEventListener(Event.OPEN,kshs);

sywj.addEventListener(ProgressEvent.PROGRESS,jzhs);

sywj.addEventListener(PLETE,wchs);

sywj.addEventListener(IOErrorEvent.IO_ERROR,cchs);

function kshs(event) {

}

function jzhs(event) {

var jzjd:Number=int((event.bytesLoaded/event.bytesTotal)*100);

jd_txt.text="已加载:"+jzjd+"%";

jd_mc.gotoAndStop(jzjd);

jd_mc.visible=true;

}

function wchs(event) {

jd_txt.text="加载已完成";

jd_mc.visible=false;

}

function cchs(event) {

jd_txt.text="加载出错了";

}

//声音控制

tz_btn.addEventListener(MouseEvent.CLICK,tzhs);

bf_btn.addEventListener(MouseEvent.CLICK,bfhs);

zt_btn.addEventListener(MouseEvent.CLICK,zths);

function tzhs(event:MouseEvent) {

ztwz=0;

sykz.stop();

}

function bfhs(event:MouseEvent) {

sykz.stop();

sykz=sywj.play(ztwz);

}

function zths(event:MouseEvent) {

ztwz=sykz.position;

sykz.stop();

}

//控制条

var shang=hk_mc.y;

var zuo=hd_mc.x-2;

var xia=0;

var you=hd_mc.width-hk_mc.width+2;

var fk:Rectangle=new Rectangle(zuo,shang,you,xia);

var zcd;

var bfb;

var pd:Boolean=false;

hk_mc.addEventListener(MouseEvent.MOUSE_DOWN,axhk);

hk_mc.addEventListener(MouseEvent.MOUSE_UP,skhk);

stage.addEventListener(MouseEvent.MOUSE_UP,lkhk);

stage.addEventListener(Event.ENTER_FRAME,cfzx);

function axhk(event) {

pd=true;

hk_mc.startDrag(false,fk);

sykz.stop();

}

function skhk(event) {

pd=false;

hk_mc.stopDrag();

sykz=sywj.play(ztwz);

}

function lkhk(event) {

pd=false;

hk_mc.stopDrag();

sykz.stop();

sykz=sywj.play(ztwz);

}

function cfzx(event) {

zcd=sywj.length/(sywj.bytesLoaded/sywj.bytesTotal);

bfb=sykz.position/zcd;

if (pd) {

ztwz=zcd*(hk_mc.x-hd_mc.x)/(hd_mc.width-hk_mc.width);

} else {

if (zcd) {

hk_mc.x=bfb*(hd_mc.width-hk_mc.width)+hd_mc.x-2;

} else {

hk_mc.x=hd_mc.x;

}

}

}

//滑道

hd_mc.buttonMode=true;

hd_mc.addEventListener(MouseEvent.MOUSE_DOWN,axhd);

hd_mc.addEventListener(MouseEvent.MOUSE_UP,skhd);

function axhd(event) {

pd=true;

sykz.stop();

if (mouseX<(hd_mc.width-hk_mc.width)+hd_mc.x) {

hk_mc.x=mouseX-hk_mc.width/2;

} else {

hk_mc.x=(hd_mc.width-hk_mc.width)+hd_mc.x;

}

ztwz=zcd*(hk_mc.x-hd_mc.x)/(hd_mc.width-hk_mc.width);

}

function skhd(event) {

pd=false;

sykz.stop();

sykz=sywj.play(ztwz);

}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。