Flash AS制作LRC歌词同步的详细教程
2008-06-05 11:22:38 来源:WEB开发网CODE:
var lrc_txt:TextField=new TextField();
var LRCarray:Array=new Array();
var sc:SoundChannel;
public function LRCPlayer() {
lrc_txt.width=500;
lrc_txt.selectable=false;
addChild(lrc_txt);
//歌词在文本 lrc_txt 中显示
var loader:URLLoader=new URLLoader();
loader.load(new URLRequest("LRC/青花瓷.lrc"));
loader.addEventListener(Event.COMPLETE,LoadFinish);
var sound:Sound=new Sound();
sound.load(new URLRequest("Music/青花瓷.mp3"));
sc=sound.play();
//播放声音,并生成 sc 变量,SoundChannel 类的实例
stage.addEventListener(Event.ENTER_FRAME,SoundPlaying);
//实时刷新歌词
}
function SoundPlaying(evt:Event):void {
for (var i=1; i if (sc.position lrc_txt.text=LRCarray[i-1].lyric;
break;
//找到歌词,跳出循环体
}
lrc_txt.text=LRCarray[LRCarray.length-1].lyric;
//找不到歌词,说明已超出了最后一句的时间,因此显示最后一句歌词
}
}
五、全部代码(文档类 LRCPlayer.as):
CODE:
package {
import flash.display.Sprite;
import flash.net.URLRequest;
import flash.net.URLLoader;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.events.Event;
import flash.text.TextField;
import flash.system.System;
public class LRCPlayer extends Sprite {
var lrc_txt:TextField=new TextField();
var LRCarray:Array=new Array();
var sc:SoundChannel;
public function LRCPlayer() {
System.useCodePage=true;
lrc_txt.width=500;
lrc_txt.selectable=false;
addChild(lrc_txt);
var loader:URLLoader=new URLLoader();
loader.load(new URLRequest("LRC/青花瓷.lrc"));
loader.addEventListener(Event.COMPLETE,LoadFinish);
var sound:Sound=new Sound();
sound.load(new URLRequest("Music/青花瓷.mp3"));
sc=sound.play();
stage.addEventListener(Event.ENTER_FRAME,SoundPlaying);
}
function SoundPlaying(evt:Event):void {
for (var i=1; i if (sc.position lrc_txt.text=LRCarray[i-1].lyric;
break;
}
lrc_txt.text=LRCarray[LRCarray.length-1].lyric;
}
}
function LoadFinish(evt:Event):void {
var list:String=evt.target.data;
var listarray:Array=list.split("
");
var reg:RegExp=/[[0-5][0-9]:[0-5][0-9].[0-9][0-9]]/g;
for (var i=0; i var info:String=listarray[i];
var len:int=info.match(reg).length;
var timeAry:Array=info.match(reg);
var lyric:String=info.substr(len*10);
for (var k:int=0; k var obj:Object=new Object();
var ctime:String=timeAry[k];
var ntime:Number=Number(ctime.substr(1,2))*60+Number(ctime.substr(4,5));
obj.timer=ntime*1000;
obj.lyric=lyric;
LRCarray.push(obj);
}
}
LRCarray.sort(compare);
}
private function compare(paraA:Object,paraB:Object):int {
if (paraA.timer>paraB.timer) {
return 1;
}
if (paraA.timer return -1;
}
return 0;
}
}
}
- ››ASP.NET及JS中的cookie基本用法
- ››ASP.NET获取MS SQL Server安装实例
- ››asp.net实现调用百度pai 在线翻译英文转中文
- ››ASP.NET页面选项进行提示判断
- ››Asp.net定时执行程序
- ››ASP.NET中利用DataList实现图片无缝滚动
- ››ASP.NET验证控件RequiredFieldValidator
- ››ASP.NET中使用System.Net.Mail发邮件
- ››ASP.NET中获取用户控件中控件的ID
- ››ASP.NET中FileBytes写成文件并存档
- ››asp获取毫秒数
- ››asp.net报“INSERT INTO 语句的语法错误解决
更多精彩
赞助商链接