?? lrcexample1.as
字號:
?package
{
//----------------------------------------
import flash.display.Sprite;
import flash.system.System;
import flash.net.URLRequest;
import flash.utils.Timer;
import flash.events.Event;
import flash.events.TimerEvent;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.media.Sound;
import flash.media.SoundChannel;
//----------------------------------------
import AS3.data.LRC;
//----------------------------------------
public class LRCExample1 extends Sprite
{
//----------------------------------------
private var my_lrc:LRC;
//----------------------------------------
private var lrc_txt:TextField;
private var txt_tf:TextFormat;
private var song:Sound;
private var channel:SoundChannel;
//----------------------------------------
private var showRow:Number = 3;
//----------------------------------------
public function LRCExample1()
{
System.useCodePage = true;
//
this.song = new Sound();
this.song.load(new URLRequest("http://localhost/music/秋天不回來 (王強).mp3"));
this.song.addEventListener(Event.COMPLETE, this.SoundcompleteHandler);
//
this.lrc_txt = new TextField();
this.lrc_txt.x = 10;
this.lrc_txt.y = 10;
this.lrc_txt.width = 170;
this.lrc_txt.height = 95;
this.lrc_txt.background = true;
this.lrc_txt.backgroundColor = 0x1C3D7D;
this.lrc_txt.selectable = false;
this.lrc_txt.defaultTextFormat = new TextFormat(null, null, 0x80B0FF, null, null, null, null, null, "center");
//
this.addChild(this.lrc_txt);
}
//----------------------------------------
private function SoundcompleteHandler(evt:Event):void
{
this.my_lrc = new LRC();
this.my_lrc.load("http://localhost/lyrics/秋天不回來-王強.lrc");
this.my_lrc.addEventListener(Event.COMPLETE, this.LRCcompleteHandler);
}
private function LRCcompleteHandler(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.channel = this.song.play();
//
var songTimer:Timer = new Timer(1000, this.song.length / 1000);
songTimer.addEventListener(TimerEvent.TIMER, 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.channel.position + this.my_lrc.offset) && (arr[i][0] >= arr[(i-1)<0 ? 0 : (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 if (j >= 0 && j < arr.length) {
lrcText += arr[j][1] + "\n";
} else {
lrcText += "\n";
}
}
this.lrc_txt.htmlText = lrcText;
}
}
}
//----------------------------------------
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -