博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
基于flash cs3 actionscript3.0的mp3网络播放器
阅读量:6972 次
发布时间:2019-06-27

本文共 1788 字,大约阅读时间需要 5 分钟。

hot3.png

目标:建立一个音乐播放器,从别的网站下载音乐来播!

解决方案:
第一步:
舞台上拖放一个progress,一个按钮,一个inputbox,做相关设置如下:
图一
图二
图三

图四
第二步:

把下面的代码添加到第一帧中:

import fl.controls.Button;import fl.controls.ProgressBar;import fl.controls.ProgressBarMode;import flash.net.URLRequest;import flash.events.*;import flash.media.Sound;import flash.media.SoundChannel;import flash.media.SoundLoaderContext;System.useCodePage = true;var myURL:String =new String();var Isplaying:Boolean = new Boolean(false);var sound=new Sound();var channel:SoundChannel=new SoundChannel();var loadvar:SoundLoaderContext = new SoundLoaderContext(1000,true);var myrequest:URLRequest;var volcomplete:Boolean =new Boolean();//_root.filesArray = ["null","11362977554da.mp3","temp3","null","temp5","temp6"];//_root.filesNote = ["源语复述", "译入与交传", "试译", "二次源语复述", "同传","交传"];//var label[]:Label = new Label();myURL = myURLtxt.text;myButton.addEventListener(MouseEvent.CLICK,onload);function onload(evt:Event){	if (myURLtxt.text == "")	{		myURLtxt.text = "请在此输入mp3文件的地址";	}	else	{		myURL = myURLtxt.text;		loadmusic(myURL);	}}function loadmusic(str:String){	myrequest = new URLRequest(str);	if (channel.position > 0)	{		if (! volcomplete)		{			sound.close();		}		sound=new Sound();	}	sound.addEventListener(ProgressEvent.PROGRESS, progressHandler);	sound.addEventListener(Event.COMPLETE, completeHandler);	sound.load(myrequest,loadvar);	volcomplete = false;	channel = sound.play();	Isplaying = true;}function progressHandler(event:ProgressEvent){	myProgress.indeterminate = false;	myProgress.mode = ProgressBarMode.MANUAL;	myProgress.maximum = 200;	myProgress.setProgress(event.bytesLoaded*200/event.bytesTotal, myProgress.maximum);}function completeHandler(event:Event){	volcomplete = true;}

测试,放在网页中测试也不会出现警告。
(注意:要放在服务器上)

转载于:https://my.oschina.net/mickelfeng/blog/155336

你可能感兴趣的文章
网络编程之urllib
查看>>
Simple Python Dictionary :)
查看>>
c语言程序设计第六次作业--循环结构(二)
查看>>
【转】WebView的JavaScript与本地代码三种交互方式
查看>>
xml转换为对象 微信接口
查看>>
软件产品案例分析
查看>>
HTML表单
查看>>
四元数
查看>>
bzoj2125: 最短路
查看>>
P4781 【模板】拉格朗日插值
查看>>
jzoj5984. 【北大2019冬令营模拟2019.1.1】仙人掌 (分块)
查看>>
python jenkins api
查看>>
电梯调度算法的实现
查看>>
IIPC--share memory
查看>>
前端之html5和css3
查看>>
View绘制机制
查看>>
跟KingDZ学HTML5之四 继续探究Canvas之路径
查看>>
054_VisualForce Ajax 01
查看>>
Android性能优化问题总结
查看>>
html5中 背景自适应
查看>>