基于flash cs3 actionscript3.0的mp3网络播放器

本文详细介绍如何使用Flash创建一个可以从外部网站加载并播放音乐的播放器。文章提供了具体步骤和代码示例,包括如何利用Flash API进行音乐加载、进度显示及播放控制等。
目标:建立一个音乐播放器,从别的网站下载音乐来播!
解决方案:
第一步:
舞台上拖放一个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();

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;
}
测试,放在网页中测试也不会出现警告。
(注意:要放在服务器上)
需要源文件留下email
关键字:flash player 域 其它网站 mp3 下载 安全沙漏  
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值