📄 lrcexample1.as
字号:
//----------------------------------------
import AS2.data.LRC;
import AS2.events.Event;
import AS2.utils.Timer;
import AS2.utils.TimerEvent;
import AS2.utils.CFDelegate;
//----------------------------------------
class LRCExample1
{
//----------------------------------------
private var my_lrc:LRC;
//----------------------------------------
private var lrc_txt:TextField;
private var txt_tf:TextFormat;
private var song:Sound;
//----------------------------------------
private var showRow:Number = 3;
//----------------------------------------
public function LRCExample1(target:MovieClip)
{
System.useCodepage = true;
//
this.song = new Sound();
this.song.loadSound("http://localhost/music/秋天不回来 (王强).mp3");
this.song.onLoad = CFDelegate.create(this, this.SoundOnLoad);
//
this.lrc_txt = target.createTextField("lrc_txt", 1, 10, 10, 170, 95);
this.lrc_txt.html = true;
this.lrc_txt.textColor = 0x80B0FF;
this.lrc_txt.background = true;
this.lrc_txt.backgroundColor = 0x1C3D7D;
this.lrc_txt.selectable = false;
//
this.txt_tf = new TextFormat();
this.txt_tf.align = "center";
//
}
//----------------------------------------
private function SoundOnLoad(success:Boolean):Void
{
if (success) {
this.my_lrc = new LRC();
this.my_lrc.load("http://localhost/lyrics/秋天不回来-王强.lrc");
this.my_lrc.addEventListener(Event.COMPLETE, CFDelegate.create(this, this.completeHandler));
}
}
private function completeHandler(evt:Event):Void
{
this.lrc_txt.htmlText = "\n标题: " + this.my_lrc.title + "\n歌手: " + this.my_lrc.artist + "\n专辑: " + this.my_lrc.album + "\n作者: " + this.my_lrc.author;
this.lrc_txt.setTextFormat(this.txt_tf);
//
this.song.start();
//
var songTimer:Timer = new Timer(1000, Math.floor(this.song.duration / 1000));
songTimer.addEventListener(TimerEvent.TIMER, CFDelegate.create(this, this.timerHandler));
songTimer.start();
}
private function timerHandler(evt:TimerEvent):Void
{
var arr:Array = this.my_lrc.lyricsList;
for (var i = 0; i < arr.length; i++) {
if ((arr[i][0] - this.my_lrc.offset < this.song.position) && (arr[i][0] >= arr[i - 1][0])) {
var lrcText:String = "";
for (var j = (i - this.showRow); j <= (this.showRow + i); j++) {
if (j == i) {
lrcText += "<font color='#FFFFCC'>" + arr[j][1] + "</font>\n";
} else {
lrcText += (arr[j][1] == undefined) ? "\n" : arr[j][1] + "\n";
}
}
this.lrc_txt.htmlText = lrcText;
}
}
this.lrc_txt.setTextFormat(this.txt_tf);
}
//----------------------------------------
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -