⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lrcexample1.as

📁 flash强大事件机制扩展类
💻 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 + -